int main (int argc, char **argv) { int exoid, exoid1, error, idum; int CPU_word_size,IO_word_size; float version; char *cdum = 0; ex_opts(EX_VERBOSE | EX_ABORT); /* open EXODUS II files */ CPU_word_size = 0; /* sizeof(float) */ IO_word_size = 0; /* use size in file */ exoid = ex_open ("test.exo", /* filename path */ EX_READ, /* access mode = READ */ &CPU_word_size, /* CPU word size */ &IO_word_size, /* IO word size */ &version); /* ExodusII library version */ printf ("\nafter ex_open\n"); if (exoid < 0) exit(1); printf ("test.exo is an EXODUSII file; version %4.2f\n", version); printf (" CPU word size %1d\n",CPU_word_size); printf (" I/O word size %1d\n",IO_word_size); ex_inquire(exoid,EX_INQ_API_VERS, &idum, &version, cdum); printf ("EXODUSII API; version %4.2f\n", version); CPU_word_size = 8; /* this really shouldn't matter for the copy but tests the conversion routines */ IO_word_size = 4; exoid1 = ex_create ("testcp.exo", /* filename */ EX_CLOBBER|EX_NORMAL_MODEL, /* OK to overwrite, normal */ &CPU_word_size, /* CPU float word size in bytes */ &IO_word_size); /* I/O float word size in bytes */ printf ("\nafter ex_create, exoid = %3d\n",exoid1); if (exoid1 < 0) exit(1); printf (" CPU word size %1d\n",CPU_word_size); printf (" I/O word size %1d\n",IO_word_size); /* ncopts = NC_VERBOSE; */ error = ex_copy (exoid, exoid1); printf ("\nafter ex_copy, error = %3d\n", error); error = ex_close (exoid); printf ("\nafter ex_close, error = %3d\n", error); error = ex_close (exoid1); printf ("\nafter ex_close, error = %3d\n", error); return 0; }
char *do_exodus_info(char *filename) { int exoid; int size = 0; int count; char **info; int i; char *lines; char *ret_string = NULL; /* * Open the specified exodusII file, read the info records * then parse them as input to aprepro. */ exoid = open_exodus_file(filename); if (exoid < 0) return ""; count = ex_inquire_int(exoid, EX_INQ_INFO); if (count > 0) { info = (char**)malloc(count * sizeof(char*)); for (i=0; i < count; i++) { info[i] = (char*)malloc((MAX_LINE_LENGTH+1) * sizeof(char)); memset(info[i], '\0', MAX_LINE_LENGTH+1); } ex_get_info(exoid, info); /* Count total size of info records.. */ for (i=0; i<count; i++) { size += strlen(info[i]); } size += count-1; /* newlines */ lines = malloc(size * sizeof(char) + 1); if (lines) { lines[0] = '\0'; for (i=0; i<count; i++) { strcat(lines, info[i]); strcat(lines, "\n"); } NEWSTR(lines, ret_string); free(lines); } if (count > 0) { for (i=0; i < count; i++) { free(info[i]); } free(info); } ex_close(exoid); return ret_string; } else { ex_close(exoid); return ""; } }
void Excn::ExodusFile::close_all() { for(int p = 0; p < partCount_; p++) { ex_close(fileids_[p]); fileids_[p] = -1; } ex_close(outputId_); outputId_ = -1; }
void Excn::ExodusFile::close_all() { for(size_t p = 0; p < fileids_.size(); p++) { ex_close(fileids_[p]); fileids_[p] = -1; } ex_close(outputId_); outputId_ = -1; }
void wr_elem_result_exo(Exo_DB *exo, const char *filename, double ***vector, const int variable_index, const int time_step, const double time_value, struct Results_Description *rd) { int error, i; double local_time_value=time_value; /* static char *yo = "wr_elem_result_exo"; */ /* * This file must already exist. */ exo->cmode = EX_WRITE; exo->io_wordsize = 0; /* query */ exo->exoid = ex_open(filename, exo->cmode, &exo->comp_wordsize, &exo->io_wordsize, &exo->version); EH(exo->exoid, "ex_open"); #ifdef DEBUG fprintf(stderr, "\t\tfilename = \"%s\"\n", filename); fprintf(stderr, "\t\tcomp_ws = %d\n", exo->comp_wordsize); fprintf(stderr, "\t\tio_wordsize = %d\n", exo->io_wordsize); #endif error = ex_put_time (exo->exoid, time_step, &local_time_value ); EH(error, "ex_put_time"); /* If the truth table has NOT been set up, this will be really slow... */ for (i = 0; i < exo->num_elem_blocks; i++) { if (exo->elem_var_tab_exists == TRUE) { /* Only write out vals if this variable exists for the block */ if (exo->elem_var_tab[i*rd->nev + variable_index] == 1) { error = ex_put_var(exo->exoid, time_step, EX_ELEM_BLOCK, variable_index+1, exo->eb_id[i], exo->eb_num_elems[i], vector[i][variable_index]); EH(error, "ex_put_var elem"); } } else { /* write it anyway (not really recommended from a performance viewpoint) */ error = ex_put_var ( exo->exoid, time_step, EX_ELEM_BLOCK, variable_index+1, /* Convert to 1 based for exodus */ exo->eb_id[i], exo->eb_num_elems[i], vector[i][variable_index] ); EH(error, "ex_put_var elem"); } } error = ex_close ( exo->exoid ); EH(error, "ex_close"); return; }
int main(int argc, char *argv[]) { int exoid; char *filename; int cpu_word_size = 8; int io_word_size = 0; float version = 0.0; banner(); if (argc != 3) { fprintf(stderr, "ERROR: Usage is exotec2 exo_in tec_out\n\n"); exit(1); } /* Open the files... */ filename = argv[1]; exoid = ex_open(filename, EX_READ, &cpu_word_size, &io_word_size, &version); if (exoid < 0) { fprintf(stderr, "Cannot open file '%s' - exiting.\n", filename); exit(1); } /* Write the tec file... */ filename = argv[2]; tec(exoid, filename); ex_close(exoid); add_to_log(argv[0], 0.0); }
/* Close ExodusII File */ int c_ex_close(int *exoid) { int error=0; #ifdef HAVE_LIBEXOIIV2C error = ex_close(*exoid); #else FLExit("Fluidity was not configured with exodusII, reconfigure with '--with-exodusii'!"); #endif return (error); }
Excn::ExodusFile::~ExodusFile() { try { if (!keepOpen_ && myProcessor_ != 0) { ex_close(fileids_[myProcessor_]); fileids_[myProcessor_] = -1; } } catch (...) { } }
int amt_close(amt_sock_t **pSock) { int res; ex_sock_t *pExSock = (ex_sock_t *) ex_malloc(sizeof(ex_sock_t)); AMT_ERR_CHECK(pExSock!=NULL, AMT_ERR, "No Memory"); *pExSock = **(ex_sock_t **)pSock; free(*pSock); *pSock=NULL; res = ex_close(&pExSock); if (res) { return res;} return 0; }
void wr_global_result_exo( Exo_DB *exo, const char *filename, const int time_step, const int ngv, double u[] ) { /***************************************************************** * write_global_result_exo() * -- open/write/close EXODUS II db for all global values * * The output EXODUS II database contains the original model * information with some minor QA and info additions, with new * global data written. * ******************************************************************/ int error; /* * This capability is deactivated for parallel processing. * brkfix doesn't support global variables, when this * changes this restriction should be removed. TAB 3/2002 */ if( u == NULL ) return ; /* Do nothing if this is NULL */ exo->cmode = EX_WRITE; exo->io_wordsize = 0; /* query */ exo->exoid = ex_open(filename, exo->cmode, &exo->comp_wordsize, &exo->io_wordsize, &exo->version); if (exo->exoid < 0) { EH(-1,"wr_nodal_result_exo: could not open the output file"); } error = ex_put_var( exo->exoid, time_step, EX_GLOBAL, 1, 0, ngv, u ); EH(error, "ex_put_var glob_vars"); error = ex_close( exo->exoid); return; }
int main() { float version = 0.0; ex_opts(EX_VERBOSE | EX_ABORT); int CPU_word_size = 0; /* sizeof(float) */ int IO_word_size = 4; /* (4 bytes) */ /* ======================================== */ /* Create an empty exodus file */ /* ====================================== */ int exoid = ex_create("test.exo", EX_CLOBBER, &CPU_word_size, &IO_word_size); ex_close(exoid); /* ======================================== */ /* Now try to open and read the empty file */ /* ====================================== */ exoid = ex_open("test.exo", /* filename path */ EX_READ, /* access mode = READ */ &CPU_word_size, /* CPU word size */ &IO_word_size, /* IO word size */ &version); /* ExodusII library version */ printf("test.exo exoid = %d\n", exoid); { char title[MAX_LINE_LENGTH + 1]; int num_dim, num_nodes, num_elem, num_elem_blk, num_node_sets, num_side_sets; int error = ex_get_init(exoid, title, &num_dim, &num_nodes, &num_elem, &num_elem_blk, &num_node_sets, &num_side_sets); printf("after ex_get_init, error = %3d\n", error); if (error) exit(-1); else exit(0); } }
inline void writeExodusFileUsingBoxes(const std::vector<FloatBox>& boxes, const std::string &filename) { if ( boxes.size() == 0 ) { std::cerr << "Skipping writing of file. No boxes to write.\n"; return; } const int num_nodes_per_elem = 8; const int num_attr = 0; const unsigned num_elements = boxes.size(); std::vector<int> numElementsPerBlock; fillNumElementsPerBlock(num_elements, numElementsPerBlock); const int num_blocks = numElementsPerBlock.size(); const int exoid = openFileAndGetId(boxes.size(), num_blocks, filename); putCoordinatesInFile(exoid, boxes); std::vector<int> connect(numElementsPerBlock[0]*num_nodes_per_elem); int ordering[8] = { 4, 3, 2, 1, 8, 7, 6, 5 }; // one based! unsigned offset = 0; for (int blockId=1;blockId<=num_blocks;blockId++) { const int num_elements_this_block = numElementsPerBlock[blockId-1]; ex_put_elem_block(exoid, blockId, "HEX", num_elements_this_block, num_nodes_per_elem, num_attr); for (int j=0;j<num_nodes_per_elem*num_elements_this_block;j++) { connect[j] = ordering[j%num_nodes_per_elem]+offset+num_nodes_per_elem*(j/num_nodes_per_elem); } offset += num_elements_this_block*num_nodes_per_elem; ex_put_elem_conn(exoid, blockId, &connect[0]); } ex_close(exoid); }
template <typename INT> std::string ExoII_Read<INT>::Close_File() { SMART_ASSERT(Check_State()); if (file_id < 0) return "ERROR: File is not open!"; int err = ex_close(file_id); if (err < 0) { std::cout << "ExoII_Read::Close_File(): ERROR " << err << ": Unable to close file! Aborting..." << '\n'; exit(1); } if (err > 0) { std::ostringstream oss; oss << "WARNING: " << err << " issued upon close"; return oss.str(); } file_id = -1; return ""; }
/*@C DMPlexCreateExodus - Create a DMPlex mesh from an ExodusII file. Collective on comm Input Parameters: + comm - The MPI communicator . filename - The name of the ExodusII file - interpolate - Create faces and edges in the mesh Output Parameter: . dm - The DM object representing the mesh Level: beginner .keywords: mesh,ExodusII .seealso: DMPLEX, DMCreate(), DMPlexCreateExodus() @*/ PetscErrorCode DMPlexCreateExodusFromFile(MPI_Comm comm, const char filename[], PetscBool interpolate, DM *dm) { PetscMPIInt rank; PetscErrorCode ierr; #if defined(PETSC_HAVE_EXODUSII) int CPU_word_size = 0, IO_word_size = 0, exoid = -1; float version; #endif PetscFunctionBegin; PetscValidCharPointer(filename, 2); ierr = MPI_Comm_rank(comm, &rank);CHKERRQ(ierr); #if defined(PETSC_HAVE_EXODUSII) if (!rank) { exoid = ex_open(filename, EX_READ, &CPU_word_size, &IO_word_size, &version); if (exoid <= 0) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_LIB, "ex_open(\"%s\",...) did not return a valid file ID", filename); } ierr = DMPlexCreateExodus(comm, exoid, interpolate, dm);CHKERRQ(ierr); if (!rank) {ierr = ex_close(exoid);CHKERRQ(ierr);} #else SETERRQ(comm, PETSC_ERR_SUP, "This method requires ExodusII support. Reconfigure using --download-exodusii"); #endif PetscFunctionReturn(0); }
void exodus_file_close(exodus_file_t* file) { if (file->writing) { // Write a QA record. char* qa_record[1][4]; qa_record[0][0] = string_dup(polymec_executable_name()); qa_record[0][1] = string_dup(polymec_executable_name()); time_t invocation_time = polymec_invocation_time(); struct tm* time_data = localtime(&invocation_time); char date[20], instant[20]; snprintf(date, 19, "%02d/%02d/%02d", time_data->tm_mon, time_data->tm_mday, time_data->tm_year % 100); qa_record[0][2] = string_dup(date); snprintf(instant, 19, "%02d:%02d:%02d", time_data->tm_hour, time_data->tm_min, time_data->tm_sec % 60); qa_record[0][3] = string_dup(instant); ex_put_qa(file->ex_id, 1, qa_record); for (int i = 0; i < 4; ++i) string_free(qa_record[0][i]); } // Clean up. if (file->elem_block_ids != NULL) polymec_free(file->elem_block_ids); if (file->face_block_ids != NULL) polymec_free(file->face_block_ids); if (file->edge_block_ids != NULL) polymec_free(file->edge_block_ids); free_all_variable_names(file); #if POLYMEC_HAVE_MPI MPI_Info_free(&file->mpi_info); #endif ex_close(file->ex_id); }
void wr_nodal_result_exo(Exo_DB *exo, char *filename, double vector[], int variable_index, int time_step, double time_value) /***************************************************************** * write_nodal_result_exo() * -- open/write/close EXODUS II db for 1 nodal var at one * time step. * * The output EXODUS II database contains the original model * information with some minor QA and info additions, with new * nodal value solution data written. * ******************************************************************/ { char err_msg[MAX_CHAR_IN_INPUT]; int error; exo->cmode = EX_WRITE; exo->io_wordsize = 0; /* query */ exo->exoid = ex_open(filename, exo->cmode, &exo->comp_wordsize, &exo->io_wordsize, &exo->version); if (exo->exoid < 0) { sr = sprintf(err_msg, "ex_open() = %d on \"%s\" failure @ step %d, time = %g", exo->exoid, filename, time_step, time_value); EH(-1, err_msg); } error = ex_put_time(exo->exoid, time_step, &time_value); EH(error, "ex_put_time"); error = ex_put_var(exo->exoid, time_step, EX_NODAL, variable_index, 1, exo->num_nodes, vector); EH(error, "ex_put_var nodal"); error = ex_close(exo->exoid); return; }
int main (int argc, char **argv) { int exoid, num_dim, num_nodes, num_elem, num_elem_blk; int num_elem_in_block[10], num_nodes_per_elem[10]; int num_node_sets, num_side_sets, error; int *connect; int node_list[100],elem_list[100],side_list[100]; int ebids[10], ids[10]; int num_nodes_per_set[10], num_elem_per_set[10]; int num_df_per_set[10]; int df_ind[10], node_ind[10], elem_ind[10]; int num_qa_rec, num_info; int CPU_word_size,IO_word_size; float x[100], y[100], z[100]; float dist_fact[100]; char *coord_names[3], *qa_record[2][4], *info[3]; ex_opts (EX_VERBOSE|EX_ABORT); /* Specify compute and i/o word size */ CPU_word_size = 0; /* sizeof(float) */ IO_word_size = 4; /* (4 bytes) */ /* create EXODUS II file */ exoid = ex_create ("test.exo", /* filename path */ EX_CLOBBER, /* create mode */ &CPU_word_size, /* CPU float word size in bytes */ &IO_word_size); /* I/O float word size in bytes */ printf ("after ex_create for test.exo, exoid = %d\n", exoid); printf (" cpu word size: %d io word size: %d\n",CPU_word_size,IO_word_size); /* ncopts = NC_VERBOSE; */ /* initialize file with parameters */ num_dim = 3; num_nodes = 33; num_elem = 8; num_elem_blk = 8; num_node_sets = 2; num_side_sets = 9; error = ex_put_init (exoid, "This is a test", num_dim, num_nodes, num_elem, num_elem_blk, num_node_sets, num_side_sets); printf ("after ex_put_init, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } /* write nodal coordinates values and names to database */ /* Quad #1 */ x[0] = 0.0; y[0] = 0.0; z[0] = 0.0; x[1] = 1.0; y[1] = 0.0; z[1] = 0.0; x[2] = 1.0; y[2] = 1.0; z[2] = 0.0; x[3] = 0.0; y[3] = 1.0; z[3] = 0.0; /* Quad #2 */ x[4] = 1.0; y[4] = 0.0; z[4] = 0.0; x[5] = 2.0; y[5] = 0.0; z[5] = 0.0; x[6] = 2.0; y[6] = 1.0; z[6] = 0.0; x[7] = 1.0; y[7] = 1.0; z[7] = 0.0; /* Hex #1 */ x[8] = 0.0; y[8] = 0.0; z[8] = 0.0; x[9] = 10.0; y[9] = 0.0; z[9] = 0.0; x[10] = 10.0; y[10] = 0.0; z[10] =-10.0; x[11] = 1.0; y[11] = 0.0; z[11] =-10.0; x[12] = 1.0; y[12] = 10.0; z[12] = 0.0; x[13] = 10.0; y[13] = 10.0; z[13] = 0.0; x[14] = 10.0; y[14] = 10.0; z[14] =-10.0; x[15] = 1.0; y[15] = 10.0; z[15] =-10.0; /* Tetra #1 */ x[16] = 0.0; y[16] = 0.0; z[16] = 0.0; x[17] = 1.0; y[17] = 0.0; z[17] = 5.0; x[18] = 10.0; y[18] = 0.0; z[18] = 2.0; x[19] = 7.0; y[19] = 5.0; z[19] = 3.0; /* Wedge #1 */ x[20] = 3.0; y[20] = 0.0; z[20] = 6.0; x[21] = 6.0; y[21] = 0.0; z[21] = 0.0; x[22] = 0.0; y[22] = 0.0; z[22] = 0.0; x[23] = 3.0; y[23] = 2.0; z[23] = 6.0; x[24] = 6.0; y[24] = 2.0; z[24] = 2.0; x[25] = 0.0; y[25] = 2.0; z[25] = 0.0; /* Tetra #2 */ x[26] = 2.7; y[26] = 1.7; z[26] = 2.7; x[27] = 6.0; y[27] = 1.7; z[27] = 3.3; x[28] = 5.7; y[28] = 1.7; z[28] = 1.7; x[29] = 3.7; y[29] = 0.0; z[29] = 2.3; /* TriShell #1 */ x[30] = 2.7; y[30] = 1.7; z[30] = 2.7; x[31] = 6.0; y[31] = 1.7; z[31] = 3.3; x[32] = 5.7; y[32] = 1.7; z[32] = 1.7; error = ex_put_coord (exoid, x, y, z); printf ("after ex_put_coord, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } coord_names[0] = "xcoor"; coord_names[1] = "ycoor"; coord_names[2] = "zcoor"; error = ex_put_coord_names (exoid, coord_names); printf ("after ex_put_coord_names, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } /* write element block parameters */ num_elem_in_block[0] = 1; num_elem_in_block[1] = 1; num_elem_in_block[2] = 1; num_elem_in_block[3] = 1; num_elem_in_block[4] = 1; num_elem_in_block[5] = 1; num_elem_in_block[6] = 1; num_elem_in_block[7] = 1; num_nodes_per_elem[0] = 4; /* elements in block #1 are 4-node quads */ num_nodes_per_elem[1] = 4; /* elements in block #2 are 4-node quads */ num_nodes_per_elem[2] = 8; /* elements in block #3 are 8-node hexes */ num_nodes_per_elem[3] = 4; /* elements in block #4 are 4-node tetras */ num_nodes_per_elem[4] = 6; /* elements in block #5 are 6-node wedges */ num_nodes_per_elem[5] = 8; /* elements in block #6 are 8-node tetras */ num_nodes_per_elem[6] = 4; /* elements in block #7 are 4-node shells */ num_nodes_per_elem[7] = 3; /* elements in block #8 are 3-node shells */ ebids[0] = 10; ebids[1] = 11; ebids[2] = 12; ebids[3] = 13; ebids[4] = 14; ebids[5] = 15; ebids[6] = 16; ebids[7] = 17; error = ex_put_elem_block (exoid, ebids[0], "quad", num_elem_in_block[0], num_nodes_per_elem[0], 1); printf ("after ex_put_elem_block, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_elem_block (exoid, ebids[1], "quad", num_elem_in_block[1], num_nodes_per_elem[1], 1); printf ("after ex_put_elem_block, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_elem_block (exoid, ebids[2], "hex", num_elem_in_block[2], num_nodes_per_elem[2], 1); printf ("after ex_put_elem_block, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_elem_block (exoid, ebids[3], "tetra", num_elem_in_block[3], num_nodes_per_elem[3], 1); printf ("after ex_put_elem_block, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_elem_block (exoid, ebids[4], "wedge", num_elem_in_block[4], num_nodes_per_elem[4], 1); printf ("after ex_put_elem_block, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_elem_block (exoid, ebids[5], "tetra", num_elem_in_block[5], num_nodes_per_elem[5], 1); printf ("after ex_put_elem_block, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_elem_block (exoid, ebids[6], "shell", num_elem_in_block[6], num_nodes_per_elem[6], 1); printf ("after ex_put_elem_block, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_elem_block (exoid, ebids[7], "triangle", num_elem_in_block[7], num_nodes_per_elem[7], 1); printf ("after ex_put_elem_block, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } /* write element connectivity */ connect = (int *) calloc(8, sizeof(int)); connect[0] = 1; connect[1] = 2; connect[2] = 3; connect[3] = 4; error = ex_put_elem_conn (exoid, ebids[0], connect); printf ("after ex_put_elem_conn, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } connect[0] = 5; connect[1] = 6; connect[2] = 7; connect[3] = 8; error = ex_put_elem_conn (exoid, ebids[1], connect); printf ("after ex_put_elem_conn, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } connect[0] = 9; connect[1] = 10; connect[2] = 11; connect[3] = 12; connect[4] = 13; connect[5] = 14; connect[6] = 15; connect[7] = 16; error = ex_put_elem_conn (exoid, ebids[2], connect); printf ("after ex_put_elem_conn, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } connect[0] = 17; connect[1] = 18; connect[2] = 19; connect[3] = 20; error = ex_put_elem_conn (exoid, ebids[3], connect); printf ("after ex_put_elem_conn, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } connect[0] = 21; connect[1] = 22; connect[2] = 23; connect[3] = 24; connect[4] = 25; connect[5] = 26; error = ex_put_elem_conn (exoid, ebids[4], connect); printf ("after ex_put_elem_conn, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } connect[0] = 17; connect[1] = 18; connect[2] = 19; connect[3] = 20; connect[4] = 27; connect[5] = 28; connect[6] = 30; connect[7] = 29; error = ex_put_elem_conn (exoid, ebids[5], connect); printf ("after ex_put_elem_conn, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } connect[0] = 1; connect[1] = 2; connect[2] = 3; connect[3] = 4; error = ex_put_elem_conn (exoid, ebids[6], connect); printf ("after ex_put_elem_conn, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } connect[0] = 30; connect[1] = 31; connect[2] = 32; error = ex_put_elem_conn (exoid, ebids[7], connect); printf ("after ex_put_elem_conn, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } free (connect); /* write individual side sets */ /* side set #1 - quad */ /* THIS SECTION IS COMMENTED OUT error = ex_put_side_set_param (exoid, 30, 2, 4); printf ("after ex_put_side_set_param, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } elem_list[0] = 2; elem_list[1] = 2; side_list[0] = 4; side_list[1] = 2; dist_fact[0] = 30.0; dist_fact[1] = 30.1; dist_fact[2] = 30.2; dist_fact[3] = 30.3; error = ex_put_side_set (exoid, 30, elem_list, side_list); printf ("after ex_put_side_set, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_side_set_dist_fact (exoid, 30, dist_fact); printf ("after ex_put_side_set_dist_fact, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } END COMMENTED OUT SECTION */ /* side set #2 - quad, spanning 2 elements */ /* THIS SECTION IS COMMENTED OUT error = ex_put_side_set_param (exoid, 31, 2, 4); printf ("after ex_put_side_set_param, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } elem_list[0] = 1; elem_list[1] = 2; side_list[0] = 2; side_list[1] = 3; dist_fact[0] = 31.0; dist_fact[1] = 31.1; dist_fact[2] = 31.2; dist_fact[3] = 31.3; error = ex_put_side_set (exoid, 31, elem_list, side_list); printf ("after ex_put_side_set, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_side_set_dist_fact (exoid, 31, dist_fact); printf ("after ex_put_side_set_dist_fact, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } END COMMENTED OUT SECTION */ /* side set #3 - hex */ /* THIS SECTION IS COMMENTED OUT error = ex_put_side_set_param (exoid, 32, 7, 0); printf ("after ex_put_side_set_param, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } elem_list[0] = 3; elem_list[1] = 3; elem_list[2] = 3; elem_list[3] = 3; elem_list[4] = 3; elem_list[5] = 3; elem_list[6] = 3; side_list[0] = 5; side_list[1] = 3; side_list[2] = 3; side_list[3] = 2; side_list[4] = 4; side_list[5] = 1; side_list[6] = 6; error = ex_put_side_set (exoid, 32, elem_list, side_list); printf ("after ex_put_side_set, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } END COMMENTED OUT SECTION */ /* side set #4 - 4-node tetras */ /* THIS SECTION IS COMMENTED OUT error = ex_put_side_set_param (exoid, 33, 4, 0); printf ("after ex_put_side_set_param, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } elem_list[0] = 4; elem_list[1] = 4; elem_list[2] = 4; elem_list[3] = 4; side_list[0] = 1; side_list[1] = 2; side_list[2] = 3; side_list[3] = 4; error = ex_put_side_set (exoid, 33, elem_list, side_list); printf ("after ex_put_side_set, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } END COMMENTED OUT SECTION */ /* side set #5 - shells; front and back faces */ /* THIS SECTION IS COMMENTED OUT error = ex_put_side_set_param (exoid, 34, 2, 0); printf ("after ex_put_side_set_param, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } elem_list[0] = 7; elem_list[1] = 7; side_list[0] = 1; side_list[1] = 2; error = ex_put_side_set (exoid, 34, elem_list, side_list); printf ("after ex_put_side_set, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } END COMMENTED OUT SECTION */ /* side set #6 - shells; edges */ /* THIS SECTION IS COMMENTED OUT error = ex_put_side_set_param (exoid, 35, 4, 0); printf ("after ex_put_side_set_param, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } elem_list[0] = 7; elem_list[1] = 7; elem_list[2] = 7; elem_list[3] = 7; side_list[0] = 3; side_list[1] = 4; side_list[2] = 5; side_list[3] = 6; error = ex_put_side_set (exoid, 35, elem_list, side_list); printf ("after ex_put_side_set, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } END COMMENTED OUT SECTION */ /* write concatenated side sets; this produces the same information as * the above code which writes individual side sets */ ids[0] = 30; ids[1] = 31; ids[2] = 32; ids[3] = 33; ids[4] = 34; ids[5] = 35; ids[6] = 36; ids[7] = 37; ids[8] = 38; /* side set #1 - NULL side set */ /* do nothing except set num_elem_per_set to 0 */ /* side set #2 - NULL side set */ /* do nothing except set num_elem_per_set to 0 */ /* side set #3 - quad; 2 sides */ node_list[0] = 8; node_list[1] = 5; elem_list[0] = 2; node_list[2] = 6; node_list[3] = 7; elem_list[1] = 2; /* side set #4 - quad; 2 sides spanning 2 elements */ node_list[4] = 2; node_list[5] = 3; elem_list[2] = 1; node_list[6] = 7; node_list[7] = 8; elem_list[3] = 2; /* side set #5 - hex; 7 sides */ node_list[8] = 9; node_list[9] = 12; node_list[10] = 11; node_list[11] = 10; elem_list[4] = 3; node_list[12] = 11; node_list[13] = 12; node_list[14] = 16; node_list[15] = 15; elem_list[5] = 3; node_list[16] = 16; node_list[17] = 15; node_list[18] = 11; node_list[19] = 12; elem_list[6] = 3; node_list[20] = 10; node_list[21] = 11; node_list[22] = 15; node_list[23] = 14; elem_list[7] = 3; node_list[24] = 13; node_list[25] = 16; node_list[26] = 12; node_list[27] = 9; elem_list[8] = 3; node_list[28] = 14; node_list[29] = 13; node_list[30] = 9; node_list[31] = 10; elem_list[9] = 3; node_list[32] = 16; node_list[33] = 13; node_list[34] = 14; node_list[35] = 15; elem_list[10] = 3; /* side set #6 - 4-node tetras; 4 sides */ node_list[36] = 17; node_list[37] = 18; node_list[38] = 20; elem_list[11] = 4; node_list[39] = 18; node_list[40] = 19; node_list[41] = 20; elem_list[12] = 4; node_list[42] = 17; node_list[43] = 20; node_list[44] = 19; elem_list[13] = 4; node_list[45] = 17; node_list[46] = 19; node_list[47] = 18; elem_list[14] = 4; /* side set #7 - shells; front and back faces */ node_list[48] = 1; node_list[49] = 2; node_list[50] = 3; node_list[51] = 4; elem_list[15] = 7; node_list[52] = 4; node_list[53] = 3; node_list[54] = 2; node_list[55] = 1; elem_list[16] = 7; /* side set #8 - shells; 4 edges */ node_list[56] = 1; node_list[57] = 2; elem_list[17] = 7; node_list[58] = 2; node_list[59] = 3; elem_list[18] = 7; node_list[60] = 3; node_list[61] = 4; elem_list[19] = 7; node_list[62] = 4; node_list[63] = 1; elem_list[20] = 7; /* side set #9 -- 3-node shells -- front and back */ node_list[64] = 30; node_list[65] = 31; node_list[66] = 32; elem_list[21] = 8; node_list[67] = 32; node_list[68] = 31; node_list[69] = 30; elem_list[22] = 8; /* set up indices */ node_ind[0] = 0; node_ind[1] = 0; node_ind[2] = 0; node_ind[3] = 4; node_ind[4] = 8; node_ind[5] = 36; node_ind[6] = 48; node_ind[7] = 56; node_ind[8] = 64; num_elem_per_set[0] = 0; num_elem_per_set[1] = 0; num_elem_per_set[2] = 2; num_elem_per_set[3] = 2; num_elem_per_set[4] = 7; num_elem_per_set[5] = 4; num_elem_per_set[6] = 2; num_elem_per_set[7] = 4; num_elem_per_set[8] = 2; num_nodes_per_set[0] = 0; num_nodes_per_set[1] = 0; num_nodes_per_set[2] = 4; num_nodes_per_set[3] = 4; num_nodes_per_set[4] = 28; num_nodes_per_set[5] = 12; num_nodes_per_set[6] = 8; num_nodes_per_set[7] = 8; num_nodes_per_set[8] = 6; elem_ind[0] = 0; elem_ind[1] = 0; elem_ind[2] = 0; elem_ind[3] = 2; elem_ind[4] = 4; elem_ind[5] = 11; elem_ind[6] = 15; elem_ind[7] = 17; elem_ind[8] = 21; error = ex_cvt_nodes_to_sides(exoid, num_elem_per_set, num_nodes_per_set, elem_ind, node_ind, elem_list, node_list, side_list); printf ("after ex_cvt_nodes_to_sides, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } num_df_per_set[0] = 0; num_df_per_set[1] = 0; num_df_per_set[2] = 4; num_df_per_set[3] = 4; num_df_per_set[4] = 0; num_df_per_set[5] = 0; num_df_per_set[6] = 0; num_df_per_set[7] = 0; num_df_per_set[8] = 0; df_ind[0] = 0; df_ind[1] = 0; df_ind[2] = 0; df_ind[3] = 4; df_ind[4] = 0; df_ind[5] = 0; df_ind[6] = 0; df_ind[7] = 0; df_ind[8] = 0; dist_fact[0] = 30.0; dist_fact[1] = 30.1; dist_fact[2] = 30.2; dist_fact[3] = 30.3; dist_fact[4] = 31.0; dist_fact[5] = 31.1; dist_fact[6] = 31.2; dist_fact[7] = 31.3; error = ex_put_concat_side_sets (exoid, ids, num_elem_per_set, num_df_per_set, elem_ind, df_ind, elem_list, side_list, dist_fact); printf ("after ex_put_concat_side_sets, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } /* THIS SECTION IS COMMENTED OUT END COMMENTED OUT SECTION */ /* write QA records; test empty and just blank-filled records */ num_qa_rec = 2; qa_record[0][0] = "TESTWT"; qa_record[0][1] = "testwt"; qa_record[0][2] = "07/07/93"; qa_record[0][3] = "15:41:33"; qa_record[1][0] = ""; qa_record[1][1] = " "; qa_record[1][2] = ""; qa_record[1][3] = " "; error = ex_put_qa (exoid, num_qa_rec, qa_record); printf ("after ex_put_qa, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } /* write information records; test empty and just blank-filled records */ num_info = 3; info[0] = "This is the first information record."; info[1] = ""; info[2] = " "; error = ex_put_info (exoid, num_info, info); printf ("after ex_put_info, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } /* close the EXODUS files */ error = ex_close (exoid); printf ("after ex_close, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } return 0; }
int main(int argc, char **argv) { int exoid, num_dim, num_nodes, num_elem, num_elem_blk, num_node_sets; int num_side_sets, error; int i, j, k, node_ctr; int *elem_map, *connect, *node_list, *node_ctr_list, *elem_list, *side_list; int *ids; int *num_nodes_per_set = NULL; int *num_elem_per_set = NULL; int *num_df_per_set = NULL; int *node_ind = NULL; int *elem_ind = NULL; int *df_ind = NULL; int num_qa_rec, num_info; int num_glo_vars, num_nod_vars, num_ele_vars; int num_nset_vars, num_sset_vars; int *truth_tab; int num_time_steps; int *num_elem_in_block = NULL; int *num_nodes_per_elem = NULL; int *num_attr = NULL; int num_nodes_in_set, num_elem_in_set; int num_sides_in_set, num_df_in_set; int list_len, elem_list_len, node_list_len, df_list_len; int node_num, time_step, var_index, beg_time, end_time, elem_num; int CPU_word_size, IO_word_size; int num_props, prop_value, *prop_values; int idum; float time_value, *time_values, *var_values; float *x, *y, *z; float *attrib, *dist_fact; float version, fdum; char *coord_names[3], *qa_record[2][4], *info[3], *var_names[3]; char *block_names[10], *nset_names[10], *sset_names[10]; char *attrib_names[10]; char name[MAX_STR_LENGTH + 1]; char title[MAX_LINE_LENGTH + 1], elem_type[MAX_STR_LENGTH + 1]; char title_chk[MAX_LINE_LENGTH + 1]; char *cdum = 0; char *prop_names[3]; CPU_word_size = 0; /* sizeof(float) */ IO_word_size = 0; /* use what is stored in file */ ex_opts(EX_VERBOSE | EX_ABORT); /* open EXODUS II files */ exoid = ex_open("test.exo", /* filename path */ EX_READ, /* access mode = READ */ &CPU_word_size, /* CPU word size */ &IO_word_size, /* IO word size */ &version); /* ExodusII library version */ printf("\nafter ex_open\n"); if (exoid < 0) exit(1); printf("test.exo is an EXODUSII file; version %4.2f\n", version); /* printf (" CPU word size %1d\n",CPU_word_size); */ printf(" I/O word size %1d\n", IO_word_size); ex_inquire(exoid, EX_INQ_API_VERS, &idum, &version, cdum); printf("EXODUSII API; version %4.2f\n", version); ex_inquire(exoid, EX_INQ_LIB_VERS, &idum, &version, cdum); printf("EXODUSII Library API; version %4.2f (%d)\n", version, idum); /* read database parameters */ error = ex_get_init(exoid, title, &num_dim, &num_nodes, &num_elem, &num_elem_blk, &num_node_sets, &num_side_sets); printf("after ex_get_init, error = %3d\n", error); printf("database parameters:\n"); printf("title = '%s'\n", title); printf("num_dim = %3d\n", num_dim); printf("num_nodes = %3d\n", num_nodes); printf("num_elem = %3d\n", num_elem); printf("num_elem_blk = %3d\n", num_elem_blk); printf("num_node_sets = %3d\n", num_node_sets); printf("num_side_sets = %3d\n", num_side_sets); /* Check that ex_inquire gives same title */ error = ex_inquire(exoid, EX_INQ_TITLE, &idum, &fdum, title_chk); printf(" after ex_inquire, error = %d\n", error); if (strcmp(title, title_chk) != 0) { printf("error in ex_inquire for EX_INQ_TITLE\n"); } /* read nodal coordinates values and names from database */ x = (float *)calloc(num_nodes, sizeof(float)); if (num_dim >= 2) y = (float *)calloc(num_nodes, sizeof(float)); else y = 0; if (num_dim >= 3) z = (float *)calloc(num_nodes, sizeof(float)); else z = 0; error = ex_get_coord(exoid, x, y, z); printf("\nafter ex_get_coord, error = %3d\n", error); printf("x coords = \n"); for (i = 0; i < num_nodes; i++) { printf("%5.1f\n", x[i]); } if (num_dim >= 2) { printf("y coords = \n"); for (i = 0; i < num_nodes; i++) { printf("%5.1f\n", y[i]); } } if (num_dim >= 3) { printf("z coords = \n"); for (i = 0; i < num_nodes; i++) { printf("%5.1f\n", z[i]); } } /* error = ex_get_1_coord (exoid, 2, x, y, z); printf ("\nafter ex_get_1_coord, error = %3d\n", error); printf ("x coord of node 2 = \n"); printf ("%f \n", x[0]); printf ("y coord of node 2 = \n"); printf ("%f \n", y[0]); */ free(x); if (num_dim >= 2) free(y); if (num_dim >= 3) free(z); for (i = 0; i < num_dim; i++) { coord_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); } error = ex_get_coord_names(exoid, coord_names); printf("\nafter ex_get_coord_names, error = %3d\n", error); printf("x coord name = '%s'\n", coord_names[0]); if (num_dim > 1) printf("y coord name = '%s'\n", coord_names[1]); if (num_dim > 2) printf("z coord name = '%s'\n", coord_names[2]); for (i = 0; i < num_dim; i++) free(coord_names[i]); { int num_attrs = 0; error = ex_get_attr_param(exoid, EX_NODAL, 0, &num_attrs); printf(" after ex_get_attr_param, error = %d\n", error); printf("num nodal attributes = %d\n", num_attrs); if (num_attrs > 0) { for (j = 0; j < num_attrs; j++) { attrib_names[j] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); } error = ex_get_attr_names(exoid, EX_NODAL, 0, attrib_names); printf(" after ex_get_attr_names, error = %d\n", error); if (error == 0) { attrib = (float *)calloc(num_nodes, sizeof(float)); for (j = 0; j < num_attrs; j++) { printf("nodal attribute %d = '%s'\n", j, attrib_names[j]); error = ex_get_one_attr(exoid, EX_NODAL, 0, j + 1, attrib); printf(" after ex_get_one_attr, error = %d\n", error); for (i = 0; i < num_nodes; i++) { printf("%5.1f\n", attrib[i]); } free(attrib_names[j]); } free(attrib); } } } /* read element order map */ elem_map = (int *)calloc(num_elem, sizeof(int)); error = ex_get_map(exoid, elem_map); printf("\nafter ex_get_map, error = %3d\n", error); for (i = 0; i < num_elem; i++) { printf("elem_map(%d) = %d \n", i, elem_map[i]); } free(elem_map); /* read element block parameters */ if (num_elem_blk > 0) { ids = (int *)calloc(num_elem_blk, sizeof(int)); num_elem_in_block = (int *)calloc(num_elem_blk, sizeof(int)); num_nodes_per_elem = (int *)calloc(num_elem_blk, sizeof(int)); num_attr = (int *)calloc(num_elem_blk, sizeof(int)); error = ex_get_elem_blk_ids(exoid, ids); printf("\nafter ex_get_elem_blk_ids, error = %3d\n", error); for (i = 0; i < num_elem_blk; i++) { block_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); } error = ex_get_names(exoid, EX_ELEM_BLOCK, block_names); printf("\nafter ex_get_names, error = %3d\n", error); for (i = 0; i < num_elem_blk; i++) { ex_get_name(exoid, EX_ELEM_BLOCK, ids[i], name); if (strcmp(name, block_names[i]) != 0) { printf("error in ex_get_name for block id %d\n", ids[i]); } error = ex_get_elem_block(exoid, ids[i], elem_type, &(num_elem_in_block[i]), &(num_nodes_per_elem[i]), &(num_attr[i])); printf("\nafter ex_get_elem_block, error = %d\n", error); printf("element block id = %2d\n", ids[i]); printf("element type = '%s'\n", elem_type); printf("num_elem_in_block = %2d\n", num_elem_in_block[i]); printf("num_nodes_per_elem = %2d\n", num_nodes_per_elem[i]); printf("num_attr = %2d\n", num_attr[i]); printf("name = '%s'\n", block_names[i]); free(block_names[i]); } /* read element block properties */ error = ex_inquire(exoid, EX_INQ_EB_PROP, &num_props, &fdum, cdum); printf("\nafter ex_inquire, error = %d\n", error); printf("\nThere are %2d properties for each element block\n", num_props); for (i = 0; i < num_props; i++) { prop_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); } error = ex_get_prop_names(exoid, EX_ELEM_BLOCK, prop_names); printf("after ex_get_prop_names, error = %d\n", error); for (i = 1; i < num_props; i++) /* Prop 1 is id; skip that here */ { for (j = 0; j < num_elem_blk; j++) { error = ex_get_prop(exoid, EX_ELEM_BLOCK, ids[j], prop_names[i], &prop_value); if (error == 0) printf("element block %2d, property(%2d): '%s'= %5d\n", j + 1, i + 1, prop_names[i], prop_value); else printf("after ex_get_prop, error = %d\n", error); } } for (i = 0; i < num_props; i++) free(prop_names[i]); } /* read element connectivity */ for (i = 0; i < num_elem_blk; i++) { if (num_elem_in_block[i] > 0) { connect = (int *)calloc((num_nodes_per_elem[i] * num_elem_in_block[i]), sizeof(int)); error = ex_get_elem_conn(exoid, ids[i], connect); printf("\nafter ex_get_elem_conn, error = %d\n", error); printf("connect array for elem block %2d\n", ids[i]); for (j = 0; j < num_nodes_per_elem[i]; j++) { printf("%3d\n", connect[j]); } /* error = ex_get_1_elem_conn (exoid, 1, ids[i], connect); printf ("\nafter ex_get_elem_conn, error = %d\n", error); printf ("node list for first element of element block %d \n ", ids[i]); for (j=0; j<num_nodes_per_elem[i]; j++) { printf ("%d \n", connect[j]); } */ free(connect); } } /* read element block attributes */ for (i = 0; i < num_elem_blk; i++) { if (num_elem_in_block[i] > 0) { for (j = 0; j < num_attr[i]; j++) attrib_names[j] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); attrib = (float *)calloc(num_attr[i] * num_elem_in_block[i], sizeof(float)); error = ex_get_elem_attr(exoid, ids[i], attrib); printf("\n after ex_get_elem_attr, error = %d\n", error); if (error == 0) { error = ex_get_elem_attr_names(exoid, ids[i], attrib_names); printf(" after ex_get_elem_attr_names, error = %d\n", error); if (error == 0) { printf("element block %d attribute '%s' = %6.4f\n", ids[i], attrib_names[0], *attrib); } } free(attrib); for (j = 0; j < num_attr[i]; j++) free(attrib_names[j]); } } if (num_elem_blk > 0) { free(ids); free(num_nodes_per_elem); free(num_attr); } /* read individual node sets */ if (num_node_sets > 0) { ids = (int *)calloc(num_node_sets, sizeof(int)); error = ex_get_node_set_ids(exoid, ids); printf("\nafter ex_get_node_set_ids, error = %3d\n", error); for (i = 0; i < num_node_sets; i++) { nset_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); } error = ex_get_names(exoid, EX_NODE_SET, nset_names); printf("\nafter ex_get_names, error = %3d\n", error); for (i = 0; i < num_node_sets; i++) { ex_get_name(exoid, EX_NODE_SET, ids[i], name); if (strcmp(name, nset_names[i]) != 0) { printf("error in ex_get_name for nodeset id %d\n", ids[i]); } error = ex_get_node_set_param(exoid, ids[i], &num_nodes_in_set, &num_df_in_set); printf("\nafter ex_get_node_set_param, error = %3d\n", error); printf("\nnode set %2d parameters: \n", ids[i]); printf("num_nodes = %2d\n", num_nodes_in_set); printf("name = '%s'\n", nset_names[i]); free(nset_names[i]); node_list = (int *)calloc(num_nodes_in_set, sizeof(int)); dist_fact = (float *)calloc(num_nodes_in_set, sizeof(float)); error = ex_get_node_set(exoid, ids[i], node_list); printf("\nafter ex_get_node_set, error = %3d\n", error); if (num_df_in_set > 0) { error = ex_get_node_set_dist_fact(exoid, ids[i], dist_fact); printf("\nafter ex_get_node_set_dist_fact, error = %3d\n", error); } printf("\nnode list for node set %2d\n", ids[i]); for (j = 0; j < num_nodes_in_set; j++) { printf("%3d\n", node_list[j]); } if (num_df_in_set > 0) { printf("dist factors for node set %2d\n", ids[i]); for (j = 0; j < num_df_in_set; j++) { printf("%5.2f\n", dist_fact[j]); } } else printf("no dist factors for node set %2d\n", ids[i]); free(node_list); free(dist_fact); { int num_attrs = 0; error = ex_get_attr_param(exoid, EX_NODE_SET, ids[i], &num_attrs); printf(" after ex_get_attr_param, error = %d\n", error); printf("num nodeset attributes for nodeset %d = %d\n", ids[i], num_attrs); if (num_attrs > 0) { for (j = 0; j < num_attrs; j++) { attrib_names[j] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); } error = ex_get_attr_names(exoid, EX_NODE_SET, ids[i], attrib_names); printf(" after ex_get_attr_names, error = %d\n", error); if (error == 0) { attrib = (float *)calloc(num_nodes_in_set, sizeof(float)); for (j = 0; j < num_attrs; j++) { printf("nodeset attribute %d = '%s'\n", j, attrib_names[j]); error = ex_get_one_attr(exoid, EX_NODE_SET, ids[i], j + 1, attrib); printf(" after ex_get_one_attr, error = %d\n", error); for (k = 0; k < num_nodes_in_set; k++) { printf("%5.1f\n", attrib[k]); } free(attrib_names[j]); } free(attrib); } } } } free(ids); /* read node set properties */ error = ex_inquire(exoid, EX_INQ_NS_PROP, &num_props, &fdum, cdum); printf("\nafter ex_inquire, error = %d\n", error); printf("\nThere are %2d properties for each node set\n", num_props); for (i = 0; i < num_props; i++) { prop_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); } prop_values = (int *)calloc(num_node_sets, sizeof(int)); error = ex_get_prop_names(exoid, EX_NODE_SET, prop_names); printf("after ex_get_prop_names, error = %d\n", error); for (i = 0; i < num_props; i++) { error = ex_get_prop_array(exoid, EX_NODE_SET, prop_names[i], prop_values); if (error == 0) for (j = 0; j < num_node_sets; j++) printf("node set %2d, property(%2d): '%s'= %5d\n", j + 1, i + 1, prop_names[i], prop_values[j]); else printf("after ex_get_prop_array, error = %d\n", error); } for (i = 0; i < num_props; i++) free(prop_names[i]); free(prop_values); /* read concatenated node sets; this produces the same information as * the above code which reads individual node sets */ error = ex_inquire(exoid, EX_INQ_NODE_SETS, &num_node_sets, &fdum, cdum); printf("\nafter ex_inquire, error = %3d\n", error); ids = (int *)calloc(num_node_sets, sizeof(int)); num_nodes_per_set = (int *)calloc(num_node_sets, sizeof(int)); num_df_per_set = (int *)calloc(num_node_sets, sizeof(int)); node_ind = (int *)calloc(num_node_sets, sizeof(int)); df_ind = (int *)calloc(num_node_sets, sizeof(int)); error = ex_inquire(exoid, EX_INQ_NS_NODE_LEN, &list_len, &fdum, cdum); printf("\nafter ex_inquire: EX_INQ_NS_NODE_LEN = %d, error = %3d\n", list_len, error); node_list = (int *)calloc(list_len, sizeof(int)); error = ex_inquire(exoid, EX_INQ_NS_DF_LEN, &list_len, &fdum, cdum); printf("\nafter ex_inquire: EX_INQ_NS_DF_LEN = %d, error = %3d\n", list_len, error); dist_fact = (float *)calloc(list_len, sizeof(float)); error = ex_get_concat_node_sets(exoid, ids, num_nodes_per_set, num_df_per_set, node_ind, df_ind, node_list, dist_fact); printf("\nafter ex_get_concat_node_sets, error = %3d\n", error); printf("\nconcatenated node set info\n"); printf("ids = \n"); for (i = 0; i < num_node_sets; i++) printf("%3d\n", ids[i]); printf("num_nodes_per_set = \n"); for (i = 0; i < num_node_sets; i++) printf("%3d\n", num_nodes_per_set[i]); printf("node_ind = \n"); for (i = 0; i < num_node_sets; i++) printf("%3d\n", node_ind[i]); printf("node_list = \n"); for (i = 0; i < list_len; i++) printf("%3d\n", node_list[i]); printf("dist_fact = \n"); for (i = 0; i < list_len; i++) printf("%5.3f\n", dist_fact[i]); free(ids); free(df_ind); free(node_ind); free(num_df_per_set); free(node_list); free(dist_fact); } /* read individual side sets */ if (num_side_sets > 0) { ids = (int *)calloc(num_side_sets, sizeof(int)); error = ex_get_side_set_ids(exoid, ids); printf("\nafter ex_get_side_set_ids, error = %3d\n", error); for (i = 0; i < num_side_sets; i++) { sset_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); } error = ex_get_names(exoid, EX_SIDE_SET, sset_names); printf("\nafter ex_get_names, error = %3d\n", error); for (i = 0; i < num_side_sets; i++) { ex_get_name(exoid, EX_SIDE_SET, ids[i], name); if (strcmp(name, sset_names[i]) != 0) { printf("error in ex_get_name for sideset id %d\n", ids[i]); } error = ex_get_side_set_param(exoid, ids[i], &num_sides_in_set, &num_df_in_set); printf("\nafter ex_get_side_set_param, error = %3d\n", error); printf("side set %2d parameters:\n", ids[i]); printf("name = '%s'\n", sset_names[i]); printf("num_sides = %3d\n", num_sides_in_set); printf("num_dist_factors = %3d\n", num_df_in_set); free(sset_names[i]); /* Note: The # of elements is same as # of sides! */ num_elem_in_set = num_sides_in_set; elem_list = (int *)calloc(num_elem_in_set, sizeof(int)); side_list = (int *)calloc(num_sides_in_set, sizeof(int)); node_ctr_list = (int *)calloc(num_elem_in_set, sizeof(int)); node_list = (int *)calloc(num_elem_in_set * 21, sizeof(int)); dist_fact = (float *)calloc(num_df_in_set, sizeof(float)); error = ex_get_side_set(exoid, ids[i], elem_list, side_list); printf("\nafter ex_get_side_set, error = %3d\n", error); error = ex_get_side_set_node_list(exoid, ids[i], node_ctr_list, node_list); printf("\nafter ex_get_side_set_node_list, error = %3d\n", error); if (num_df_in_set > 0) { error = ex_get_side_set_dist_fact(exoid, ids[i], dist_fact); printf("\nafter ex_get_side_set_dist_fact, error = %3d\n", error); } printf("element list for side set %2d\n", ids[i]); for (j = 0; j < num_elem_in_set; j++) { printf("%3d\n", elem_list[j]); } printf("side list for side set %2d\n", ids[i]); for (j = 0; j < num_sides_in_set; j++) { printf("%3d\n", side_list[j]); } node_ctr = 0; printf("node list for side set %2d\n", ids[i]); for (k = 0; k < num_elem_in_set; k++) { for (j = 0; j < node_ctr_list[k]; j++) { printf("%3d\n", node_list[node_ctr + j]); } node_ctr += node_ctr_list[k]; } if (num_df_in_set > 0) { printf("dist factors for side set %2d\n", ids[i]); for (j = 0; j < num_df_in_set; j++) { printf("%5.3f\n", dist_fact[j]); } } else printf("no dist factors for side set %2d\n", ids[i]); free(elem_list); free(side_list); free(node_ctr_list); free(node_list); free(dist_fact); } /* read side set properties */ error = ex_inquire(exoid, EX_INQ_SS_PROP, &num_props, &fdum, cdum); printf("\nafter ex_inquire, error = %d\n", error); printf("\nThere are %2d properties for each side set\n", num_props); for (i = 0; i < num_props; i++) { prop_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); } error = ex_get_prop_names(exoid, EX_SIDE_SET, prop_names); printf("after ex_get_prop_names, error = %d\n", error); for (i = 0; i < num_props; i++) { for (j = 0; j < num_side_sets; j++) { error = ex_get_prop(exoid, EX_SIDE_SET, ids[j], prop_names[i], &prop_value); if (error == 0) printf("side set %2d, property(%2d): '%s'= %5d\n", j + 1, i + 1, prop_names[i], prop_value); else printf("after ex_get_prop, error = %d\n", error); } } for (i = 0; i < num_props; i++) free(prop_names[i]); free(ids); error = ex_inquire(exoid, EX_INQ_SIDE_SETS, &num_side_sets, &fdum, cdum); printf("\nafter ex_inquire: EX_INQ_SIDE_SETS = %d, error = %d\n", num_side_sets, error); if (num_side_sets > 0) { error = ex_inquire(exoid, EX_INQ_SS_ELEM_LEN, &elem_list_len, &fdum, cdum); printf("\nafter ex_inquire: EX_INQ_SS_ELEM_LEN = %d, error = %d\n", elem_list_len, error); error = ex_inquire(exoid, EX_INQ_SS_NODE_LEN, &node_list_len, &fdum, cdum); printf("\nafter ex_inquire: EX_INQ_SS_NODE_LEN = %d, error = %d\n", node_list_len, error); error = ex_inquire(exoid, EX_INQ_SS_DF_LEN, &df_list_len, &fdum, cdum); printf("\nafter ex_inquire: EX_INQ_SS_DF_LEN = %d, error = %d\n", df_list_len, error); } /* read concatenated side sets; this produces the same information as * the above code which reads individual side sets */ /* concatenated side set read */ if (num_side_sets > 0) { ids = (int *)calloc(num_side_sets, sizeof(int)); num_elem_per_set = (int *)calloc(num_side_sets, sizeof(int)); num_df_per_set = (int *)calloc(num_side_sets, sizeof(int)); elem_ind = (int *)calloc(num_side_sets, sizeof(int)); df_ind = (int *)calloc(num_side_sets, sizeof(int)); elem_list = (int *)calloc(elem_list_len, sizeof(int)); side_list = (int *)calloc(elem_list_len, sizeof(int)); dist_fact = (float *)calloc(df_list_len, sizeof(float)); error = ex_get_concat_side_sets(exoid, ids, num_elem_per_set, num_df_per_set, elem_ind, df_ind, elem_list, side_list, dist_fact); printf("\nafter ex_get_concat_side_sets, error = %3d\n", error); printf("concatenated side set info\n"); printf("ids = \n"); for (i = 0; i < num_side_sets; i++) printf("%3d\n", ids[i]); printf("num_elem_per_set = \n"); for (i = 0; i < num_side_sets; i++) printf("%3d\n", num_elem_per_set[i]); printf("num_dist_per_set = \n"); for (i = 0; i < num_side_sets; i++) printf("%3d\n", num_df_per_set[i]); printf("elem_ind = \n"); for (i = 0; i < num_side_sets; i++) printf("%3d\n", elem_ind[i]); printf("dist_ind = \n"); for (i = 0; i < num_side_sets; i++) printf("%3d\n", df_ind[i]); printf("elem_list = \n"); for (i = 0; i < elem_list_len; i++) printf("%3d\n", elem_list[i]); printf("side_list = \n"); for (i = 0; i < elem_list_len; i++) printf("%3d\n", side_list[i]); printf("dist_fact = \n"); for (i = 0; i < df_list_len; i++) printf("%5.3f\n", dist_fact[i]); free(ids); free(num_df_per_set); free(df_ind); free(elem_ind); free(elem_list); free(side_list); free(dist_fact); } } /* end of concatenated side set read */ /* read QA records */ ex_inquire(exoid, EX_INQ_QA, &num_qa_rec, &fdum, cdum); for (i = 0; i < num_qa_rec; i++) { for (j = 0; j < 4; j++) { qa_record[i][j] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); } } error = ex_get_qa(exoid, qa_record); printf("\nafter ex_get_qa, error = %3d\n", error); printf("QA records = \n"); for (i = 0; i < num_qa_rec; i++) { for (j = 0; j < 4; j++) { printf(" '%s'\n", qa_record[i][j]); free(qa_record[i][j]); } } /* read information records */ error = ex_inquire(exoid, EX_INQ_INFO, &num_info, &fdum, cdum); printf("\nafter ex_inquire, error = %3d\n", error); for (i = 0; i < num_info; i++) { info[i] = (char *)calloc((MAX_LINE_LENGTH + 1), sizeof(char)); } error = ex_get_info(exoid, info); printf("\nafter ex_get_info, error = %3d\n", error); printf("info records = \n"); for (i = 0; i < num_info; i++) { printf(" '%s'\n", info[i]); free(info[i]); } /* read global variables parameters and names */ error = ex_get_var_param(exoid, "g", &num_glo_vars); printf("\nafter ex_get_var_param, error = %3d\n", error); for (i = 0; i < num_glo_vars; i++) { var_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); } error = ex_get_var_names(exoid, "g", num_glo_vars, var_names); printf("\nafter ex_get_var_names, error = %3d\n", error); printf("There are %2d global variables; their names are :\n", num_glo_vars); for (i = 0; i < num_glo_vars; i++) { printf(" '%s'\n", var_names[i]); free(var_names[i]); } /* read nodal variables parameters and names */ num_nod_vars = 0; if (num_nodes > 0) { error = ex_get_var_param(exoid, "n", &num_nod_vars); printf("\nafter ex_get_var_param, error = %3d\n", error); for (i = 0; i < num_nod_vars; i++) { var_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); } error = ex_get_var_names(exoid, "n", num_nod_vars, var_names); printf("\nafter ex_get_var_names, error = %3d\n", error); printf("There are %2d nodal variables; their names are :\n", num_nod_vars); for (i = 0; i < num_nod_vars; i++) { printf(" '%s'\n", var_names[i]); free(var_names[i]); } } /* read element variables parameters and names */ num_ele_vars = 0; if (num_elem > 0) { error = ex_get_var_param(exoid, "e", &num_ele_vars); printf("\nafter ex_get_var_param, error = %3d\n", error); for (i = 0; i < num_ele_vars; i++) { var_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); } error = ex_get_var_names(exoid, "e", num_ele_vars, var_names); printf("\nafter ex_get_var_names, error = %3d\n", error); printf("There are %2d element variables; their names are :\n", num_ele_vars); for (i = 0; i < num_ele_vars; i++) { printf(" '%s'\n", var_names[i]); free(var_names[i]); } /* read element variable truth table */ if (num_ele_vars > 0) { truth_tab = (int *)calloc((num_elem_blk * num_ele_vars), sizeof(int)); error = ex_get_elem_var_tab(exoid, num_elem_blk, num_ele_vars, truth_tab); printf("\nafter ex_get_elem_var_tab, error = %3d\n", error); printf("This is the element variable truth table:\n"); k = 0; for (i = 0; i < num_elem_blk * num_ele_vars; i++) { printf("%2d\n", truth_tab[k++]); } free(truth_tab); } } /* read nodeset variables parameters and names */ num_nset_vars = 0; if (num_node_sets > 0) { error = ex_get_var_param(exoid, "m", &num_nset_vars); printf("\nafter ex_get_var_param, error = %3d\n", error); if (num_nset_vars > 0) { for (i = 0; i < num_nset_vars; i++) { var_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); } error = ex_get_var_names(exoid, "m", num_nset_vars, var_names); printf("\nafter ex_get_var_names, error = %3d\n", error); printf("There are %2d nodeset variables; their names are :\n", num_nset_vars); for (i = 0; i < num_nset_vars; i++) { printf(" '%s'\n", var_names[i]); free(var_names[i]); } /* read nodeset variable truth table */ if (num_nset_vars > 0) { truth_tab = (int *)calloc((num_node_sets * num_nset_vars), sizeof(int)); error = ex_get_nset_var_tab(exoid, num_node_sets, num_nset_vars, truth_tab); printf("\nafter ex_get_nset_var_tab, error = %3d\n", error); printf("This is the nodeset variable truth table:\n"); k = 0; for (i = 0; i < num_node_sets * num_nset_vars; i++) { printf("%2d\n", truth_tab[k++]); } free(truth_tab); } } } /* read sideset variables parameters and names */ num_sset_vars = 0; if (num_side_sets > 0) { error = ex_get_var_param(exoid, "s", &num_sset_vars); printf("\nafter ex_get_var_param, error = %3d\n", error); if (num_sset_vars > 0) { for (i = 0; i < num_sset_vars; i++) { var_names[i] = (char *)calloc((MAX_STR_LENGTH + 1), sizeof(char)); } error = ex_get_var_names(exoid, "s", num_sset_vars, var_names); printf("\nafter ex_get_var_names, error = %3d\n", error); printf("There are %2d sideset variables; their names are :\n", num_sset_vars); for (i = 0; i < num_sset_vars; i++) { printf(" '%s'\n", var_names[i]); free(var_names[i]); } /* read sideset variable truth table */ if (num_sset_vars > 0) { truth_tab = (int *)calloc((num_side_sets * num_sset_vars), sizeof(int)); error = ex_get_sset_var_tab(exoid, num_side_sets, num_sset_vars, truth_tab); printf("\nafter ex_get_sset_var_tab, error = %3d\n", error); printf("This is the sideset variable truth table:\n"); k = 0; for (i = 0; i < num_side_sets * num_sset_vars; i++) { printf("%2d\n", truth_tab[k++]); } free(truth_tab); } } } /* determine how many time steps are stored */ error = ex_inquire(exoid, EX_INQ_TIME, &num_time_steps, &fdum, cdum); printf("\nafter ex_inquire, error = %3d\n", error); printf("There are %2d time steps in the database.\n", num_time_steps); /* read time value at one time step */ time_step = 3; error = ex_get_time(exoid, time_step, &time_value); printf("\nafter ex_get_time, error = %3d\n", error); printf("time value at time step %2d = %5.3f\n", time_step, time_value); /* read time values at all time steps */ time_values = (float *)calloc(num_time_steps, sizeof(float)); error = ex_get_all_times(exoid, time_values); printf("\nafter ex_get_all_times, error = %3d\n", error); printf("time values at all time steps are:\n"); for (i = 0; i < num_time_steps; i++) printf("%5.3f\n", time_values[i]); free(time_values); /* read all global variables at one time step */ var_values = (float *)calloc(num_glo_vars, sizeof(float)); error = ex_get_glob_vars(exoid, time_step, num_glo_vars, var_values); printf("\nafter ex_get_glob_vars, error = %3d\n", error); printf("global variable values at time step %2d\n", time_step); for (i = 0; i < num_glo_vars; i++) printf("%5.3f\n", var_values[i]); free(var_values); /* read a single global variable through time */ var_index = 1; beg_time = 1; end_time = -1; var_values = (float *)calloc(num_time_steps, sizeof(float)); error = ex_get_glob_var_time(exoid, var_index, beg_time, end_time, var_values); printf("\nafter ex_get_glob_var_time, error = %3d\n", error); printf("global variable %2d values through time:\n", var_index); for (i = 0; i < num_time_steps; i++) printf("%5.3f\n", var_values[i]); free(var_values); /* read a nodal variable at one time step */ if (num_nodes > 0) { var_values = (float *)calloc(num_nodes, sizeof(float)); error = ex_get_nodal_var(exoid, time_step, var_index, num_nodes, var_values); printf("\nafter ex_get_nodal_var, error = %3d\n", error); printf("nodal variable %2d values at time step %2d\n", var_index, time_step); for (i = 0; i < num_nodes; i++) printf("%5.3f\n", var_values[i]); free(var_values); /* read a nodal variable through time */ var_values = (float *)calloc(num_time_steps, sizeof(float)); node_num = 1; error = ex_get_nodal_var_time(exoid, var_index, node_num, beg_time, end_time, var_values); printf("\nafter ex_get_nodal_var_time, error = %3d\n", error); printf("nodal variable %2d values for node %2d through time:\n", var_index, node_num); for (i = 0; i < num_time_steps; i++) printf("%5.3f\n", var_values[i]); free(var_values); } /* read an element variable at one time step */ if (num_elem_blk > 0) { ids = (int *)calloc(num_elem_blk, sizeof(int)); error = ex_get_elem_blk_ids(exoid, ids); printf("\n after ex_get_elem_blk_ids, error = %3d\n", error); for (i = 0; i < num_elem_blk; i++) { if (num_elem_in_block[i] > 0) { var_values = (float *)calloc(num_elem_in_block[i], sizeof(float)); error = ex_get_elem_var(exoid, time_step, var_index, ids[i], num_elem_in_block[i], var_values); printf("\nafter ex_get_elem_var, error = %3d\n", error); if (!error) { printf("element variable %2d values of element block %2d at time step %2d\n", var_index, ids[i], time_step); for (j = 0; j < num_elem_in_block[i]; j++) printf("%5.3f\n", var_values[j]); } free(var_values); } } free(num_elem_in_block); free(ids); } /* read an element variable through time */ if (num_ele_vars > 0) { var_values = (float *)calloc(num_time_steps, sizeof(float)); var_index = 2; elem_num = 2; error = ex_get_elem_var_time(exoid, var_index, elem_num, beg_time, end_time, var_values); printf("\nafter ex_get_elem_var_time, error = %3d\n", error); printf("element variable %2d values for element %2d through time:\n", var_index, elem_num); for (i = 0; i < num_time_steps; i++) printf("%5.3f\n", var_values[i]); free(var_values); } /* read a sideset variable at one time step */ if (num_sset_vars > 0) { ids = (int *)calloc(num_side_sets, sizeof(int)); error = ex_get_side_set_ids(exoid, ids); printf("\n after ex_get_side_set_ids, error = %3d\n", error); for (i = 0; i < num_side_sets; i++) { var_values = (float *)calloc(num_elem_per_set[i], sizeof(float)); error = ex_get_sset_var(exoid, time_step, var_index, ids[i], num_elem_per_set[i], var_values); printf("\nafter ex_get_sset_var, error = %3d\n", error); if (!error) { printf("sideset variable %2d values of sideset %2d at time step %2d\n", var_index, ids[i], time_step); for (j = 0; j < num_elem_per_set[i]; j++) printf("%5.3f\n", var_values[j]); } free(var_values); } free(num_elem_per_set); free(ids); } /* read a nodeset variable at one time step */ if (num_nset_vars > 0) { ids = (int *)calloc(num_node_sets, sizeof(int)); error = ex_get_node_set_ids(exoid, ids); printf("\n after ex_get_node_set_ids, error = %3d\n", error); for (i = 0; i < num_node_sets; i++) { var_values = (float *)calloc(num_nodes_per_set[i], sizeof(float)); error = ex_get_nset_var(exoid, time_step, var_index, ids[i], num_nodes_per_set[i], var_values); printf("\nafter ex_get_nset_var, error = %3d\n", error); if (!error) { printf("nodeset variable %2d values of nodeset %2d at time step %2d\n", var_index, ids[i], time_step); for (j = 0; j < num_nodes_per_set[i]; j++) printf("%5.3f\n", var_values[j]); } free(var_values); } free(ids); } if (num_node_sets > 0) free(num_nodes_per_set); error = ex_close(exoid); printf("\nafter ex_close, error = %3d\n", error); return 0; }
int main (int argc, char **argv) { int exoid, num_dim, num_nodes, num_elem, num_elem_blk; int num_elem_in_block[10], num_nodes_per_elem[10]; int num_nodes_in_nset[10]; int num_node_sets, num_side_sets; int i, j, k, m, *elem_map, *connect; int node_list[100]; int ebids[10], nsids[10]; int num_qa_rec, num_info; int num_glo_vars, num_nod_vars, num_ele_vars, num_nset_vars; int *truth_tab; int whole_time_step, num_time_steps; int CPU_word_size,IO_word_size; int prop_array[2]; float *glob_var_vals, *nodal_var_vals, *elem_var_vals; float *nset_var_vals; float time_value; float x[100]; float attrib[10], dist_fact[100]; char *coord_names[3], *qa_record[2][4], *info[3], *var_names[3]; char *block_names[10], *nset_names[10]; char *prop_names[2], *attrib_names[2]; char *title = "This is a test"; ex_opts (EX_VERBOSE | EX_ABORT ); /* Specify compute and i/o word size */ CPU_word_size = 0; /* sizeof(float) */ IO_word_size = 4; /* (4 bytes) */ /* create EXODUS II file */ exoid = ex_create ("oned.e", /* filename path */ EX_CLOBBER, /* create mode */ &CPU_word_size, /* CPU float word size in bytes */ &IO_word_size); /* I/O float word size in bytes */ printf ("after ex_create for oned.e, exoid = %d\n", exoid); printf (" cpu word size: %d io word size: %d\n",CPU_word_size,IO_word_size); EXCHECK(ex_set_max_name_length(exoid, 40)); /* ncopts = NC_VERBOSE; */ /* initialize file with parameters */ num_dim = 1; num_nodes = 10; num_elem = 10; /* 9 lines plus a point */ num_elem_blk = 3; num_node_sets = 2; num_side_sets = 0; EXCHECK(ex_put_init (exoid, title, num_dim, num_nodes, num_elem, num_elem_blk, num_node_sets, num_side_sets)); for (i=0; i < num_nodes; i++) { x[i] = exp((float)i/10.0); } EXCHECK(ex_put_coord (exoid, x, NULL, NULL)); coord_names[0] = "xcoor"; EXCHECK(ex_put_coord_names (exoid, coord_names)); /* Add nodal attributes */ EXCHECK(ex_put_attr_param(exoid, EX_NODAL, 0, 1)); EXCHECK(ex_put_one_attr(exoid, EX_NODAL, 0, 1, x)); attrib_names[0] = "Node_attr_1"; EXCHECK(ex_put_attr_names (exoid, EX_NODAL, 0, attrib_names)); /* write element order map */ elem_map = (int *) calloc(num_elem, sizeof(int)); for (i=1; i<=num_elem; i++) { elem_map[i-1] = 10*i; } EXCHECK(ex_put_map (exoid, elem_map)); free (elem_map); /* write element block parameters */ block_names[0] = "left_side"; block_names[1] = "right_side"; block_names[2] = "center"; num_elem_in_block[0] = 4; num_elem_in_block[1] = 5; num_elem_in_block[2] = 1; num_nodes_per_elem[0] = 2; num_nodes_per_elem[1] = 2; num_nodes_per_elem[2] = 1; ebids[0] = 10; ebids[1] = 20; ebids[2] = 30; EXCHECK(ex_put_elem_block (exoid, ebids[0], "line", num_elem_in_block[0], num_nodes_per_elem[0], 1)); EXCHECK(ex_put_elem_block (exoid, ebids[1], "line", num_elem_in_block[1], num_nodes_per_elem[1], 1)); EXCHECK(ex_put_elem_block (exoid, ebids[2], "point", num_elem_in_block[2], num_nodes_per_elem[2], 0)); /* Write element block names */ EXCHECK(ex_put_names(exoid, EX_ELEM_BLOCK, block_names)); /* write element block properties */ prop_names[0] = "DENSITY"; EXCHECK(ex_put_prop_names(exoid,EX_ELEM_BLOCK,1,prop_names)); EXCHECK(ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[0], prop_names[0], 1.345)); EXCHECK(ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[1], prop_names[0], 10.995)); EXCHECK(ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[2], prop_names[0], 0.001)); /* write element connectivity */ connect = (int *) calloc(18, sizeof(int)); for (i=0; i < num_elem*2; i+=2) { connect[i] = i/2+1; connect[i+1] = i/2+2; } EXCHECK(ex_put_conn (exoid, EX_ELEM_BLOCK, ebids[0], connect, NULL, NULL)); EXCHECK(ex_put_conn (exoid, EX_ELEM_BLOCK, ebids[1], connect+8, NULL, NULL)); /* Circle */ connect[0] = 5; EXCHECK(ex_put_conn (exoid, EX_ELEM_BLOCK, ebids[2], connect, NULL, NULL)); /* write element block attributes */ for (i=0; i < num_elem; i++) { attrib[i] = 3.14159 * i; } EXCHECK(ex_put_attr (exoid, EX_ELEM_BLOCK, ebids[0], attrib)); EXCHECK(ex_put_attr (exoid, EX_ELEM_BLOCK, ebids[1], attrib+num_elem_in_block[0])); attrib_names[0] = "THICKNESS"; EXCHECK(ex_put_attr_names (exoid, EX_ELEM_BLOCK, ebids[0], attrib_names)); attrib_names[0] = "WIDTH"; EXCHECK(ex_put_attr_names (exoid, EX_ELEM_BLOCK, ebids[1], attrib_names)); /* write individual node sets */ num_nodes_in_nset[0] = 5; num_nodes_in_nset[1] = 3; nsids[0] = 20; nsids[1] = 21; EXCHECK(ex_put_node_set_param (exoid, nsids[0], 5, 5)); node_list[0] = 1; node_list[1] = 3; node_list[2] = 5; node_list[3] = 7; node_list[4] = 9; dist_fact[0] = 1.0; dist_fact[1] = 2.0; dist_fact[2] = 3.0; dist_fact[3] = 4.0; dist_fact[4] = 5.0; EXCHECK(ex_put_node_set (exoid, nsids[0], node_list)); EXCHECK(ex_put_node_set_dist_fact (exoid, nsids[0], dist_fact)); EXCHECK(ex_put_node_set_param (exoid, nsids[1], 3, 3)); node_list[0] = 2; node_list[1] = 4; node_list[2] = 6; dist_fact[0] = 1.0; dist_fact[1] = 2.0; dist_fact[2] = 3.0; EXCHECK(ex_put_node_set (exoid, nsids[1], node_list)); EXCHECK(ex_put_node_set_dist_fact (exoid, nsids[1], dist_fact)); /* Write node set names */ nset_names[0] = "all_odd_nodes"; nset_names[1] = "some_even_nodes"; EXCHECK(ex_put_names(exoid, EX_NODE_SET, nset_names)); EXCHECK(ex_put_prop(exoid, EX_NODE_SET, nsids[0], "FACE", 4)); EXCHECK(ex_put_prop(exoid, EX_NODE_SET, nsids[1], "FACE", 5)); prop_array[0] = 1000; prop_array[1] = 2000; EXCHECK(ex_put_prop_array(exoid, EX_NODE_SET, "VELOCITY", prop_array)); /* Add nodeset attributes */ EXCHECK(ex_put_attr_param(exoid, EX_NODE_SET, nsids[0], 1)); EXCHECK(ex_put_attr(exoid, EX_NODE_SET, nsids[0], x)); attrib_names[0] = "Nodeset_attribute"; EXCHECK(ex_put_attr_names (exoid, EX_NODE_SET, nsids[0], attrib_names)); /* write QA records; test empty and just blank-filled records */ num_qa_rec = 2; qa_record[0][0] = "TESTWT"; qa_record[0][1] = "testwt"; qa_record[0][2] = "07/07/93"; qa_record[0][3] = "15:41:33"; qa_record[1][0] = ""; qa_record[1][1] = " "; qa_record[1][2] = ""; qa_record[1][3] = " "; EXCHECK(ex_put_qa (exoid, num_qa_rec, qa_record)); /* write information records; test empty and just blank-filled records */ num_info = 3; info[0] = "This is the first information record."; info[1] = ""; info[2] = " "; EXCHECK(ex_put_info (exoid, num_info, info)); /* write results variables parameters and names */ num_glo_vars = 1; var_names[0] = "glo_vars"; EXCHECK(ex_put_variable_param (exoid, EX_GLOBAL, num_glo_vars)); EXCHECK(ex_put_variable_names (exoid, EX_GLOBAL, num_glo_vars, var_names)); num_nod_vars = 2; /* 12345678901234567890123456789012 */ var_names[0] = "node_variable_a_very_long_name_0"; var_names[1] = "nod_var1"; EXCHECK(ex_put_variable_param (exoid, EX_NODAL, num_nod_vars)); EXCHECK(ex_put_variable_names (exoid, EX_NODAL, num_nod_vars, var_names)); num_ele_vars = 3; /* 0 1 2 3 */ /* 12345678901234567890123456789012 */ var_names[0] = "this_variable_name_is_short"; var_names[1] = "this_variable_name_is_just_right"; var_names[2] = "this_variable_name_is_tooooo_long"; EXCHECK(ex_put_variable_param (exoid, EX_ELEM_BLOCK, num_ele_vars)); EXCHECK(ex_put_variable_names (exoid, EX_ELEM_BLOCK, num_ele_vars, var_names)); num_nset_vars = 3; var_names[0] = "ns_var0"; var_names[1] = "ns_var1"; var_names[2] = "ns_var2"; EXCHECK(ex_put_variable_param (exoid, EX_NODE_SET, num_nset_vars)); EXCHECK(ex_put_variable_names (exoid, EX_NODE_SET, num_nset_vars, var_names)); /* write element variable truth table */ truth_tab = (int *) calloc ((num_elem_blk*num_ele_vars), sizeof(int)); k = 0; for (i=0; i<num_elem_blk; i++) { for (j=0; j<num_ele_vars; j++) { truth_tab[k++] = 1; } } EXCHECK(ex_put_truth_table(exoid, EX_ELEM_BLOCK, num_elem_blk, num_ele_vars, truth_tab)); free (truth_tab); /* for each time step, write the analysis results; * the code below fills the arrays glob_var_vals, * nodal_var_vals, and elem_var_vals with values for debugging purposes; */ whole_time_step = 1; num_time_steps = 10; glob_var_vals = (float *) calloc (num_glo_vars, CPU_word_size); nodal_var_vals = (float *) calloc (num_nodes, CPU_word_size); elem_var_vals = (float *) calloc (num_elem, CPU_word_size); nset_var_vals = (float *) calloc (10, CPU_word_size); for (i=0; i<num_time_steps; i++) { time_value = (float)(i+1)/100.; /* write time value */ EXCHECK(ex_put_time (exoid, whole_time_step, &time_value)); /* write global variables */ for (j=0; j<num_glo_vars; j++) { glob_var_vals[j] = (float)(j+2) * time_value; } EXCHECK(ex_put_var (exoid, whole_time_step, EX_GLOBAL, 0, 0, num_glo_vars, glob_var_vals)); /* write nodal variables */ for (k=1; k<=num_nod_vars; k++) { for (j=0; j<num_nodes; j++) { nodal_var_vals[j] = (float)k + ((float)(j+1) * time_value); } EXCHECK(ex_put_var (exoid, whole_time_step, EX_NODAL, k, 1, num_nodes, nodal_var_vals)); } /* write element variables */ for (k=1; k<=num_ele_vars; k++) { for (j=0; j<num_elem_blk; j++) { for (m=0; m<num_elem_in_block[j]; m++) { elem_var_vals[m] = (float)(k+1) + (float)(j+2) + ((float)(m+1)*time_value); } EXCHECK(ex_put_var (exoid, whole_time_step, EX_ELEM_BLOCK, k, ebids[j], num_elem_in_block[j], elem_var_vals)); } } /* write nodeset variables */ for (k=1; k<=num_nset_vars; k++) { for (j=0; j<num_node_sets; j++) { for (m=0; m<num_nodes_in_nset[j]; m++) { nset_var_vals[m] = (float)(k+3) + (float)(j+4) + ((float)(m+1)*time_value); } EXCHECK(ex_put_var (exoid, whole_time_step, EX_NODE_SET, k, nsids[j], num_nodes_in_nset[j], nset_var_vals)); } } whole_time_step++; /* update the data file; this should be done at the end of every time step * to ensure that no data is lost if the analysis dies */ EXCHECK(ex_update (exoid)); } free(glob_var_vals); free(nodal_var_vals); free(elem_var_vals); free(nset_var_vals); /* close the EXODUS files */ EXCHECK(ex_close (exoid)); return 0; }
int main(int argc, char *argv[]) { const char *salsa_cmd_file; int c; double g_start_t = second(); bool force_64_bit = false; int start_proc = 0; int num_proc = 0; int subcycles = 0; int cycle = -1; while ((c = getopt(argc, argv, "64Vhp:r:s:n:S:c:")) != -1) { switch (c) { case 'h': fprintf(stderr, " usage:\n"); fprintf(stderr, "\tnem_spread [-s <start_proc>] [-n <num_proc>] [-S <subcycles> -c <cycle>] [command_file]\n"); fprintf(stderr, "\t\tDecompose for processors <start_proc> to <start_proc>+<num_proc>\n"); fprintf(stderr, "\t\tDecompose for cycle <cycle> of <subcycle> groups\n"); fprintf(stderr, "\tnem_spread [-V] [-h] (show version or usage info)\n"); fprintf(stderr, "\tnem_spread [command file] [<-p Proc> <-r raid #>]\n"); exit(1); break; case 'V': printf("%s version %s\n", UTIL_NAME, VER_STR); exit(0); break; case 'p': /* Which proc to use? Also for compatability */ break; case 'r': /* raid number. Seems to be unused; left around for compatability */ break; case 's': /* Start with processor <x> */ sscanf(optarg, "%d", &start_proc); break; case 'n': /* Number of processors to output files for */ sscanf(optarg, "%d", &num_proc); break; case '6': case '4': force_64_bit = true; /* Force storing output mesh using 64bit integers */ break; case 'S': /* Number of subcycles to use (see below) */ sscanf(optarg, "%d", &subcycles); break; case 'c': /* Which cycle to spread (see below) */ sscanf(optarg, "%d", &cycle); break; } } if (optind >= argc) salsa_cmd_file = "nem_spread.inp"; else { salsa_cmd_file = argv[optind]; } printf("%s version %s\n", UTIL_NAME, VER_STR); /* initialize some variables */ ExoFile[0] = '\0'; Exo_LB_File[0] = '\0'; Exo_Res_File[0] = '\0'; Debug_Flag = -1; Num_Nod_Var = -1; Num_Elem_Var = -1; Num_Glob_Var = -1; Num_Nset_Var = -1; Num_Sset_Var = -1; PIO_Info.Dsk_List_Cnt = -1; PIO_Info.Num_Dsk_Ctrlrs = -1; PIO_Info.PDsk_Add_Fact = -1; PIO_Info.Zeros = -1; PIO_Info.NoSubdirectory = 0; PIO_Info.Par_Dsk_Root[0] = '\0'; PIO_Info.Par_Dsk_SubDirec[0] = '\0'; PIO_Info.Staged_Writes[0] = '\0'; // Read the ASCII input file and get the name of the mesh file // so we can determine the floating point and integer word sizes // needed to instantiate the templates... if (read_mesh_file_name(salsa_cmd_file) < 0) { static char yo[] = "nem_spread"; fprintf(stderr,"%s ERROR: Could not read in the the I/O command file" " \"%s\"!\n", yo, salsa_cmd_file); exit(1); } // Open the mesh file and determine word sizes... int io_ws = 0; int cpu_ws = sizeof(float); float version; int exoid = ex_open (ExoFile, EX_READ, &cpu_ws, &io_ws, &version); // See if any 64-bit integers stored on database... int int64api = 0; int int64db = ex_int64_status(exoid) & EX_ALL_INT64_DB; if (int64db != 0) { int64api = EX_ALL_INT64_API; } int status; if (io_ws == 4) { if (int64api) { NemSpread<float, int64_t> spreader; spreader.io_ws = io_ws; spreader.int64db = int64db; spreader.int64api = int64api; spreader.force64db = force_64_bit; spreader.Proc_Info[4] = start_proc; spreader.Proc_Info[5] = num_proc; status = nem_spread(spreader, salsa_cmd_file, subcycles, cycle); } else { NemSpread<float, int> spreader; spreader.io_ws = io_ws; spreader.int64db = int64db; spreader.int64api = int64api; spreader.force64db = force_64_bit; spreader.Proc_Info[4] = start_proc; spreader.Proc_Info[5] = num_proc; status = nem_spread(spreader, salsa_cmd_file, subcycles, cycle); } } else { if (int64api) { NemSpread<double, int64_t> spreader; spreader.io_ws = io_ws; spreader.int64db = int64db; spreader.int64api = int64api; spreader.force64db = force_64_bit; spreader.Proc_Info[4] = start_proc; spreader.Proc_Info[5] = num_proc; status = nem_spread(spreader, salsa_cmd_file, subcycles, cycle); } else { NemSpread<double, int> spreader; spreader.io_ws = io_ws; spreader.int64db = int64db; spreader.int64api = int64api; spreader.force64db = force_64_bit; spreader.Proc_Info[4] = start_proc; spreader.Proc_Info[5] = num_proc; status = nem_spread(spreader, salsa_cmd_file, subcycles, cycle); } } double g_end_t = second() - g_start_t; printf("The average run time was: %.2fs\n", g_end_t); ex_close(exoid); add_to_log(argv[0], g_end_t); return status; }
int main (int argc, char **argv) { int exoid, num_dim, num_nodes, num_elem, num_elem_blk; int num_node_sets, num_side_sets, error; int i, j; int num_qa_rec, num_info; int num_glo_vars; int whole_time_step, num_time_steps; int CPU_word_size,IO_word_size; float *glob_var_vals; float time_value; char *coord_names[3], *qa_record[2][4], *info[3], *var_names[3]; ex_opts (EX_VERBOSE | EX_ABORT ); /* Specify compute and i/o word size */ CPU_word_size = 0; /* sizeof(float) */ IO_word_size = 4; /* (4 bytes) */ /* create EXODUS II file */ exoid = ex_create ("test.exo", /* filename path */ EX_CLOBBER, /* create mode */ &CPU_word_size, /* CPU float word size in bytes */ &IO_word_size); /* I/O float word size in bytes */ printf ("after ex_create for test.exo, exoid = %d\n", exoid); printf (" cpu word size: %d io word size: %d\n",CPU_word_size,IO_word_size); /* ncopts = NC_VERBOSE; */ /* initialize file with parameters */ num_dim = 1; num_nodes = 0; num_elem = 0; num_elem_blk = 0; num_node_sets = 0; num_side_sets = 0; error = ex_put_init (exoid, "This is a test", num_dim, num_nodes, num_elem, num_elem_blk, num_node_sets, num_side_sets); printf ("after ex_put_init, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } coord_names[0] = "xcoor"; error = ex_put_coord_names (exoid, coord_names); printf ("after ex_put_coord_names, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } /* write QA records; test empty and just blank-filled records */ num_qa_rec = 2; qa_record[0][0] = "TESTWT"; qa_record[0][1] = "testwt"; qa_record[0][2] = "07/07/93"; qa_record[0][3] = "15:41:33"; qa_record[1][0] = ""; qa_record[1][1] = " "; qa_record[1][2] = ""; qa_record[1][3] = " "; error = ex_put_qa (exoid, num_qa_rec, qa_record); printf ("after ex_put_qa, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } /* write information records; test empty and just blank-filled records */ num_info = 3; info[0] = "This is the first information record."; info[1] = ""; info[2] = " "; error = ex_put_info (exoid, num_info, info); printf ("after ex_put_info, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } /* write results variables parameters and names */ num_glo_vars = 1; var_names[0] = "glo_vars"; error = ex_put_var_param (exoid, "g", num_glo_vars); printf ("after ex_put_var_param, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_var_names (exoid, "g", num_glo_vars, var_names); printf ("after ex_put_var_names, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } /* for each time step, write the analysis results; * the code below fills the arrays glob_var_vals, * nodal_var_vals, and elem_var_vals with values for debugging purposes; * obviously the analysis code will populate these arrays */ whole_time_step = 1; num_time_steps = 10; glob_var_vals = (float *) calloc (num_glo_vars, CPU_word_size); for (i=0; i<num_time_steps; i++) { time_value = (float)(i+1)/100.; /* write time value */ error = ex_put_time (exoid, whole_time_step, &time_value); printf ("after ex_put_time, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } /* write global variables */ for (j=0; j<num_glo_vars; j++) { glob_var_vals[j] = (float)(j+2) * time_value; } error = ex_put_glob_vars (exoid, whole_time_step, num_glo_vars, glob_var_vals); printf ("after ex_put_glob_vars, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } whole_time_step++; /* update the data file; this should be done at the end of every time step * to ensure that no data is lost if the analysis dies */ error = ex_update (exoid); printf ("after ex_update, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } } free(glob_var_vals); /* close the EXODUS files */ error = ex_close (exoid); printf ("after ex_close, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } return 0; }
void set_init_Element_Storage(ELEM_BLK_STRUCT *eb_ptr, int mn) /***************************************************************** * * set_init_Element_Storage() * * * like its predecessor init_element_storage, this function actually * places initial values for the draining and wetting curves for the * TANH_HYST function, according to the request in the material property * database cards for the current material * *****************************************************************/ { int ielem_type, ip_total, i, j, ifound, ip; double sat_switch = 0.0, pc_switch = 0.0, Draining_curve, *ev_tmp; int error, num_dim, num_nodes; int num_elem, num_elem_blk, num_node_sets, num_side_sets, time_step; float version; /* version number of EXODUS II */ int exoid; /* ID of the open EXODUS II file */ char title[MAX_LINE_LENGTH]; /* title of the EXODUS II database */ float ret_float; /* any returned float */ char ret_char[3]; /* any returned character */ int num_vars; /* number of var_type variables */ char **var_names = NULL; /* array containing num_vars variable names */ char appended_name[MAX_VAR_NAME_LNGTH]; /*Quick return if model is not hysteretic in nature */ if(mp_glob[mn]->SaturationModel == TANH_HYST) { ielem_type = eb_ptr->Elem_Type; ip_total = eb_ptr->IP_total; Draining_curve = mp_glob[mn]->u_saturation[8]; if (Guess_Flag ==4 || Guess_Flag == 5) { EH(-1,"Not a smooth restart for hysteretic saturation function. If you really want to do this use read_exoII_file or call us"); } if(Guess_Flag == 5 || Guess_Flag == 6) { WH(-1,"Initializing Hysteretic Curve values at all Gauss points with read_exoII_file"); CPU_word_size = sizeof(double); IO_word_size = 0; exoid = ex_open(ExoAuxFile, EX_READ, &CPU_word_size, &IO_word_size , &version); EH(exoid, "ex_open"); error = ex_get_init(exoid, title, &num_dim, &num_nodes, &num_elem, &num_elem_blk, &num_node_sets, &num_side_sets); EH(error, "ex_get_init for efv or init guess"); /* * Obtain the number of time steps in the exodus file, time_step, * We will read only from the last time step */ error = ex_inquire(exoid, EX_INQ_TIME, &time_step, &ret_float, ret_char); EH(error, "ex_inquire"); /* Based on problem type and available info in database, extract * appropriate fields */ /* * Get the number of nodal variables in the file, and allocate * space for storage of their names. */ error = ex_get_var_param(exoid, "e", &num_vars); EH(error, "ex_get_var_param"); /* First extract all nodal variable names in exoII database */ if (num_vars > 0) { var_names = alloc_VecFixedStrings(num_vars, (MAX_STR_LENGTH+1)); error = ex_get_var_names(exoid, "e", num_vars, var_names); EH(error, "ex_get_var_names"); for (i = 0; i < num_vars; i++) strip(var_names[i]); } else { fprintf(stderr, "Warning: no element variables for saturation stored in exoII input file.\n"); } /*****THIS IS WHERE YOU LOAD THEM UP ******/ ev_tmp = (double *) smalloc(eb_ptr->Num_Elems_In_Block* sizeof(double)); ifound = 0; for(ip = 0; ip < ip_total; ip++) { sprintf(appended_name, "sat_curve_type%d", ip ); for(j=0; j < num_vars; j++) { if(!strcasecmp(appended_name,var_names[j])) { /*Found variable so load it into element storage */ error = ex_get_elem_var(exoid, time_step, j+1, eb_ptr->Elem_Blk_Id, eb_ptr->Num_Elems_In_Block, ev_tmp); ifound = 1; } } if(ifound) { for (i = 0; i < eb_ptr->Num_Elems_In_Block; i++) { eb_ptr->ElemStorage[i].sat_curve_type[ip] = ev_tmp[i]; } } else { EH(-1,"Cannot find an element variable for sat. hysteresis"); } ifound = 0; sprintf(appended_name, "sat_switch%d", ip ); for(j=0; j < num_vars; j++) { if(!strcasecmp(appended_name,var_names[j])) { /*Found variable so load it into element storage */ error = ex_get_elem_var(exoid, time_step, j+1, eb_ptr->Elem_Blk_Id, eb_ptr->Num_Elems_In_Block, ev_tmp); ifound = 1; } } if(ifound) { for (i = 0; i < eb_ptr->Num_Elems_In_Block; i++) { eb_ptr->ElemStorage[i].Sat_QP_tn[ip] = ev_tmp[i]; } } else { EH(-1,"Cannot find an element variable for sat. hysteresis"); } ifound = 0; sprintf(appended_name, "pc_switch%d", ip ); for(j=0; j < num_vars; j++) { if(!strcasecmp(appended_name,var_names[j])) { /*Found variable so load it into element storage */ error = ex_get_elem_var(exoid, time_step, j+1, eb_ptr->Elem_Blk_Id, eb_ptr->Num_Elems_In_Block, ev_tmp); ifound = 1; } } if(ifound) { for (i = 0; i < eb_ptr->Num_Elems_In_Block; i++) { eb_ptr->ElemStorage[i].p_cap_QP[ip] = ev_tmp[i]; } } else { EH(-1,"Cannot find an element variable for sat. hysteresis"); } } error = ex_close(exoid); safer_free((void **) &var_names); free(ev_tmp); } else /*Initialize as dictated by input cards */ { if(Draining_curve == 1.0) { sat_switch = mp->u_saturation[0]; pc_switch = 1.e-12; } else if (Draining_curve == 0.0) { double sat_max = mp->u_saturation[0]; double sat_min = mp->u_saturation[4]; double alpha_w = mp->u_saturation[3]; double beta_w = mp->u_saturation[2]; pc_switch = 1.e12*alpha_w; sat_switch = sat_max - ( sat_max - sat_min)*0.5*(1.0+tanh( beta_w - alpha_w/pc_switch ) ) ; } else { EH(-1,"TANH_HYST must have 1.0 or 0.0 in 9th spot"); } for (i = 0; i < eb_ptr->Num_Elems_In_Block; i++) { for(ip = 0; ip < ip_total; ip++) { eb_ptr->ElemStorage[i].p_cap_QP[ip] = pc_switch; eb_ptr->ElemStorage[i].Sat_QP_tn[ip] = sat_switch; eb_ptr->ElemStorage[i].sat_curve_type[ip] = Draining_curve; } } } } if(elc_glob[mn]->thermal_expansion_model == SHRINKAGE) { ip_total = eb_ptr->IP_total; if (Guess_Flag ==4 || Guess_Flag == 5) { EH(-1,"Not a smooth restart for solidification shrinkage model.Use read_exoII_file or call us"); } if(Guess_Flag == 5 || Guess_Flag == 6) { EH(-1,"Initializing solidified shrinkage model from exoII file not available yet. Use zero"); } // Load em up as all unsolidified for(ip = 0; ip < ip_total; ip++) { for (i = 0; i < eb_ptr->Num_Elems_In_Block; i++) { eb_ptr->ElemStorage[i].solidified[ip] = 0.0; } } } }
void NemSpread<T,INT>::load_lb_info(void) /* * load_lb_info: * * This function reads and distributes the load balance information. * This information is defined as the following scalars, which are specific * to each processor: * * Num_Internal_Nodes * Num_Border_Nodes * Num_External_Nodes * globals.Num_Internal_Elems * globals.Num_Border_Elems * * and the following vectors, also specific to each processor: * * globals.GNodes [Num_Internal_Nodes+Num_Border_Nodes+Num_External_Nodes] * globals.GElems [globals.Num_Internal_Elems+globals.Num_Border_Elems] * * For the 1 processor case, this routine fills in appropriate values * for these quantities. */ { int lb_exoid=0; INT cmap_max_size=0, *comm_vec; const char *yo = "load_lb_info"; char Title[MAX_LINE_LENGTH+1]; float version; int cpu_ws=0; /******************************** START EXECUTION ****************************/ if(Debug_Flag) printf ("\nStart to read in and distribute the load balance info\n"); /* Open the Load Balance exoII file for reading */ printf ("EXODUS II load-balance file: %s\n", Exo_LB_File); cpu_ws = io_ws; int mode = EX_READ | int64api; int iio_ws = 0; // Don't interfere with exodus files; this is the nemesis file. if((lb_exoid = ex_open(Exo_LB_File, mode, &cpu_ws, &iio_ws, &version)) == -1) { fprintf(stderr, "%sERROR: Couldn\'t open lb file, %s\n", yo, Exo_LB_File); exit(1); } /* Read information about the processor configuration */ read_proc_init(lb_exoid,Proc_Info, &Proc_Ids); /* Allocate space for the counts */ globals.Num_Internal_Nodes = (INT *)array_alloc(__FILE__, __LINE__, 1, 7*Proc_Info[2], sizeof(INT)); globals.Num_Border_Nodes = globals.Num_Internal_Nodes +Proc_Info[2]; globals.Num_External_Nodes = globals.Num_Border_Nodes +Proc_Info[2]; globals.Num_Internal_Elems = globals.Num_External_Nodes +Proc_Info[2]; globals.Num_Border_Elems = globals.Num_Internal_Elems +Proc_Info[2]; globals.Num_N_Comm_Maps = globals.Num_Border_Elems +Proc_Info[2]; globals.Num_E_Comm_Maps = globals.Num_N_Comm_Maps +Proc_Info[2]; /* Allocate space for each processor entity */ globals.GNodes = (INT **)array_alloc(__FILE__, __LINE__, 1, 3*Proc_Info[2], sizeof(INT *)); globals.GElems = globals.GNodes +Proc_Info[2]; globals.Elem_Map = globals.GElems +Proc_Info[2]; /* Allocate contiguous space for the pointer vectors on all processors */ INT *Int_Space = (INT *)array_alloc(__FILE__, __LINE__, 1, (7*Proc_Info[0] + 1), sizeof(INT)); INT *Int_Node_Num = Int_Space + 1; INT *Bor_Node_Num = Int_Node_Num +Proc_Info[0]; INT *Ext_Node_Num = Bor_Node_Num +Proc_Info[0]; INT *Int_Elem_Num = Ext_Node_Num +Proc_Info[0]; INT *Bor_Elem_Num = Int_Elem_Num +Proc_Info[0]; INT *Node_Comm_Num = Bor_Elem_Num +Proc_Info[0]; INT *Elem_Comm_Num = Node_Comm_Num +Proc_Info[0]; /* Read the initial information contained in the load balance file */ read_lb_init(lb_exoid, Int_Space, Int_Node_Num, Bor_Node_Num, Ext_Node_Num, Int_Elem_Num, Bor_Elem_Num, Node_Comm_Num, Elem_Comm_Num, Title); /* Allocate memory for the communication map arrays */ globals.N_Comm_Map = (NODE_COMM_MAP<INT>**)malloc(Proc_Info[2]*sizeof(NODE_COMM_MAP<INT> *)); globals.E_Comm_Map = (ELEM_COMM_MAP<INT>**)malloc(Proc_Info[2]*sizeof(ELEM_COMM_MAP<INT> *)); if(!globals.N_Comm_Map || !globals.E_Comm_Map) { fprintf(stderr, "ERROR: Insufficient memory!\n"); exit(1); } for (int iproc=0; iproc <Proc_Info[2]; iproc++) { /* * Error check: * Currently a maximum of one nodal communication map and one * elemental communication map is supported. */ if(globals.Num_N_Comm_Maps[iproc] > 1 || globals.Num_E_Comm_Maps[iproc] > 1) { fprintf(stderr, "%s: ERROR. Only 1 nodal and elemental comm map " "is supported\n", yo); exit(1); } else { /* Always allocate at least one and initialize the counts to 0 */ globals.N_Comm_Map[iproc] = (NODE_COMM_MAP<INT> *)malloc(PEX_MAX(1, globals.Num_N_Comm_Maps[iproc]) * sizeof(NODE_COMM_MAP<INT>)); if(globals.N_Comm_Map[iproc] == NULL && globals.Num_N_Comm_Maps[iproc] > 0) { fprintf(stderr, "%s: ERROR. Insufficient memory for nodal comm. map!\n", yo); exit(1); } for(size_t ijump=0; ijump < PEX_MAX(1, globals.Num_N_Comm_Maps[iproc]); ijump++) ((globals.N_Comm_Map[iproc])+ijump)->node_cnt = 0; globals.E_Comm_Map[iproc] = (ELEM_COMM_MAP<INT> *)malloc(PEX_MAX(1, globals.Num_E_Comm_Maps[iproc]) * sizeof(ELEM_COMM_MAP<INT>)); if(globals.E_Comm_Map[iproc] == NULL && globals.Num_E_Comm_Maps[iproc] > 0) { fprintf(stderr, "%s: ERROR. Insufficient memory for elemental comm. map!\n", yo); exit(1); } for(size_t ijump=0; ijump < PEX_MAX(1, globals.Num_E_Comm_Maps[iproc]); ijump++) ((globals.E_Comm_Map[iproc])+ijump)->elem_cnt = 0; } } /* End "for (int iproc=0; iproc <Proc_Info[2]; iproc++)" */ /* Set up each processor for the communication map parameters */ read_cmap_params(lb_exoid, Node_Comm_Num, Elem_Comm_Num, globals.Num_N_Comm_Maps, globals.Num_E_Comm_Maps, globals.E_Comm_Map, globals.N_Comm_Map, &cmap_max_size, &comm_vec); /* Allocate enough space to read the LB_data for one processor */ INT *Integer_Vector = (INT *)array_alloc(__FILE__, __LINE__, 1, Int_Space[0] + cmap_max_size, sizeof (INT)); /* * loop through the processors, one at a time, to read * their load balance information * * NOTE: From here on there are no provisions for multiple nodal * or elemental communication maps. */ size_t ijump = 0; /* keep track of where in comm_vec we are */ for (int iproc = 0; iproc <Proc_Info[0]; iproc++) { /* Get the node map for processor "iproc" */ if(ex_get_processor_node_maps(lb_exoid, &Integer_Vector[0], &Integer_Vector[Int_Node_Num[iproc]], &Integer_Vector[Int_Node_Num[iproc]+ Bor_Node_Num[iproc]], iproc) < 0) { fprintf(stderr, "%s: ERROR, failed to get node map for Proc %d!\n", yo, iproc); exit(1); } size_t vec_indx = Int_Node_Num[iproc] + Bor_Node_Num[iproc] + Ext_Node_Num[iproc]; /* Get the element map for processor number "iproc" */ if(ex_get_processor_elem_maps(lb_exoid, &Integer_Vector[vec_indx], &Integer_Vector[vec_indx+Int_Elem_Num[iproc]], iproc) < 0) { fprintf(stderr, "%s: ERROR, failed to get element map for Proc %d!\n", yo, iproc); exit(1); } if(Node_Comm_Num[iproc] > 0) { vec_indx += Int_Elem_Num[iproc] + Bor_Elem_Num[iproc]; if(ex_get_node_cmap(lb_exoid, comm_vec[ijump], &Integer_Vector[vec_indx], &Integer_Vector[vec_indx+comm_vec[ijump+1]], iproc) < 0) { /* * If there are disconnected mesh pieces, then it is * possible that there is no comminication between the * pieces and there will be no communication maps. Normally * this is a problem, so output a warning, but don't abort. */ fprintf(stderr, "%s: WARNING. Failed to get nodal comm map for Proc %d!\n", yo, iproc); } } if(Elem_Comm_Num[iproc] > 0) { vec_indx += 2*comm_vec[ijump+1]; if(ex_get_elem_cmap(lb_exoid, comm_vec[ijump+2], &Integer_Vector[vec_indx], &Integer_Vector[vec_indx+comm_vec[ijump+3]], &Integer_Vector[vec_indx+2*comm_vec[ijump+3]], iproc) < 0) { fprintf(stderr, "%s: ERROR. Failed to get elemental comm map for Proc %d!\n", yo, iproc); exit(1); } } /* * Communicate load balance information to the correct processor * - if iproc = Proc_Ids[*] then process the data instead. */ assert(Proc_Ids[iproc] == iproc); process_lb_data (Integer_Vector, iproc); /* * now move ijump to the next communications map * make sure to check if there are any for this processor */ if (Node_Comm_Num[iproc] > 0) ijump += 2; if (Elem_Comm_Num[iproc] > 0) ijump += 2; } /* Close the load balance file - we are finished with it */ if(ex_close (lb_exoid) == -1) { fprintf (stderr, "%sERROR: Error in closing load balance file\n", yo); exit(1); } /************************* Cleanup and Printout Phase ***********************/ /* Free temporary memory */ safe_free((void **) &Integer_Vector); if(num_qa_rec > 0) { for(int i = 0; i < length_qa; i++) safe_free((void **) &(qa_record_ptr[i])); safe_free((void **) &qa_record_ptr); } if(num_inf_rec > 0) { for(int i = 0; i < num_inf_rec; i++) safe_free((void **) &(inf_record_ptr[i])); safe_free((void **) &inf_record_ptr); } safe_free((void **) &Int_Space); safe_free((void **) &comm_vec); for (int iproc=0; iproc <Proc_Info[2]; iproc++) { if (globals.Num_Internal_Nodes[iproc] == 0 && globals.Num_Border_Nodes[iproc] == 0 && globals.Num_External_Nodes[iproc] == 0) { fprintf(stderr, "\n%s: WARNING, Processor %d has no nodes!\n", yo, iproc); } if (globals.Num_Internal_Elems[iproc] == 0 && globals.Num_Border_Elems[iproc] == 0) { fprintf(stderr, "\n%s: WARNING, Processor %d has no elements!\n", yo, iproc); } } /*========================================================================*/ if(Debug_Flag) printf ("\nFinished distributing load balance info\n"); /* Output Detailed timing information for the progam */ /* * Print out a Large table of Load Balance Information if the debug_flag * setting is large enough */ if(Debug_Flag >= 7) { printf ("\n\n"); print_line ("=", 79); for (int iproc=0; iproc <Proc_Info[2]; iproc++) { printf("\n\t***For Processor %d***\n", Proc_Ids[iproc]); printf("\tInternal nodes owned by the current processor\n\t"); for(INT i = 0; i < globals.Num_Internal_Nodes[iproc]; i++) printf(" " ST_ZU "", (size_t)globals.GNodes[iproc][i]); printf("\n"); printf("\tBorder nodes owned by the current processor\n\t"); for(INT i = 0; i < globals.Num_Border_Nodes[iproc]; i++) printf(" " ST_ZU "", (size_t)globals.GNodes[iproc][i + globals.Num_Internal_Nodes[iproc]]); printf("\n"); if(globals.Num_External_Nodes[iproc] > 0) { printf("\tExternal nodes needed by the current processor\n\t"); for(INT i = 0; i < globals.Num_External_Nodes[iproc]; i++) printf(" " ST_ZU "", (size_t)globals.GNodes[iproc][i + globals.Num_Internal_Nodes[iproc] + globals.Num_Border_Nodes[iproc]]); printf("\n"); } printf("\tInternal elements owned by the current processor\n\t"); for(INT i = 0; i < globals.Num_Internal_Elems[iproc]; i++) printf(" " ST_ZU "", (size_t)globals.GElems[iproc][i]); printf("\n"); if(globals.Num_Border_Elems[iproc] > 0) { printf("\tBorder elements owned by the current processor\n\t"); for(INT i=0; i < globals.Num_Border_Elems[iproc]; i++) printf(" " ST_ZU "", (size_t)globals.GElems[iproc][i+globals.Num_Internal_Elems[iproc]]); printf("\n"); } if(globals.Num_N_Comm_Maps[iproc] > 0) { printf("\tNodal Comm Map for the current processor\n"); printf("\t\tnode IDs:"); for(size_t i=0; i < globals.N_Comm_Map[iproc]->node_cnt; i++) printf(" " ST_ZU "", (size_t)globals.N_Comm_Map[iproc]->node_ids[i]); printf("\n\t\tproc IDs:"); for(size_t i=0; i < globals.N_Comm_Map[iproc]->node_cnt; i++) printf(" " ST_ZU "", (size_t)globals.N_Comm_Map[iproc]->proc_ids[i]); printf("\n"); } if(globals.Num_E_Comm_Maps[iproc] > 0) { printf("\tElemental Comm Map for the current processor\n"); printf("\t\telement IDs:"); for(size_t i=0; i < globals.E_Comm_Map[iproc]->elem_cnt; i++) printf(" " ST_ZU "", (size_t)globals.E_Comm_Map[iproc]->elem_ids[i]); printf("\n\t\tside IDs:"); for(size_t i=0; i < globals.E_Comm_Map[iproc]->elem_cnt; i++) printf(" " ST_ZU "", (size_t)globals.E_Comm_Map[iproc]->side_ids[i]); printf("\n\t\tproc IDs:"); for(size_t i=0; i < globals.E_Comm_Map[iproc]->elem_cnt; i++) printf(" " ST_ZU "", (size_t)globals.E_Comm_Map[iproc]->proc_ids[i]); printf("\n"); } } printf("\n"); print_line ("=", 79); } } /* END of routine load_lb_info () ******************************************/
int read_mesh(const std::string &exo_file, Problem_Description* problem, Mesh_Description<INT>* mesh, Weight_Description<INT>* weight ) { float version, *xptr, *yptr, *zptr; char elem_type[MAX_STR_LENGTH+1]; E_Type blk_elem_type; /*---------------------------Execution Begins--------------------------------*/ /* Open the ExodusII file */ int exoid, cpu_ws=0, io_ws=0; int mode = EX_READ | problem->int64api; if((exoid=ex_open(exo_file.c_str(), mode, &cpu_ws, &io_ws, &version)) < 0) { Gen_Error(0, "fatal: unable to open ExodusII mesh file"); return 0; } /* Read the coordinates, if desired */ xptr = yptr = zptr = NULL; if(problem->read_coords == ELB_TRUE) { switch(mesh->num_dims) { case 3: zptr = (mesh->coords)+2*(mesh->num_nodes); /* FALLTHRU */ case 2: yptr = (mesh->coords)+(mesh->num_nodes); /* FALLTHRU */ case 1: xptr = mesh->coords; } if(ex_get_coord(exoid, xptr, yptr, zptr) < 0) { Gen_Error(0, "fatal: unable to read coordinate values for mesh"); return 0; } } /* End "if(problem->read_coords == ELB_TRUE)" */ /* Read the element block IDs */ std::vector<INT> el_blk_ids(mesh->num_el_blks); std::vector<INT> el_blk_cnts(mesh->num_el_blks); if(ex_get_elem_blk_ids(exoid, &el_blk_ids[0]) < 0) { Gen_Error(0, "fatal: unable to read element block IDs"); return 0; } /* Read the element connectivity */ size_t gelem_cnt=0; for(size_t cnt=0; cnt < mesh->num_el_blks; cnt++) { INT nodes_per_elem, num_attr; if(ex_get_elem_block(exoid, el_blk_ids[cnt], elem_type, &(el_blk_cnts[cnt]), &nodes_per_elem, &num_attr) < 0) { Gen_Error(0, "fatal: unable to read element block"); return 0; } blk_elem_type = get_elem_type(elem_type, nodes_per_elem, mesh->num_dims); INT *blk_connect = (INT*)malloc(sizeof(INT)*el_blk_cnts[cnt]*nodes_per_elem); if(!blk_connect) { Gen_Error(0, "fatal: insufficient memory"); return 0; } /* Get the connectivity for this element block */ if(ex_get_elem_conn(exoid, el_blk_ids[cnt], blk_connect) < 0) { Gen_Error(0, "fatal: failed to get element connectivity"); return 0; } /* find out if this element block is weighted */ int wgt = -1; if (weight->type & EL_BLK) wgt = in_list(el_blk_ids[cnt], weight->elemblk); /* Fill the 2D global connectivity array */ if (((problem->type == ELEMENTAL) && (weight->type & EL_BLK)) || ((problem->type == NODAL) && (weight->type & EL_BLK))) { for(int64_t cnt2=0; cnt2 < el_blk_cnts[cnt]; cnt2++) { mesh->elem_type[gelem_cnt] = blk_elem_type; /* while going through the blocks, take care of the weighting */ if ((problem->type == ELEMENTAL) && (weight->type & EL_BLK)) { /* is this block weighted */ if (wgt >= 0) { /* check if there is a read value */ if (weight->vertices[gelem_cnt] >= 1) { /* and if it should be overwritten */ if (weight->ow_read) weight->vertices[gelem_cnt] = weight->elemblk_wgt[wgt]; } else weight->vertices[gelem_cnt] = weight->elemblk_wgt[wgt]; } else { /* now check if this weight has been initialized */ if (weight->vertices[gelem_cnt] < 1) weight->vertices[gelem_cnt] = 1; } } for(int64_t cnt3=0; cnt3 < nodes_per_elem; cnt3++) { INT node = blk_connect[cnt3 + cnt2*nodes_per_elem] - 1; assert(node >= 0); mesh->connect[gelem_cnt][cnt3] = node; /* deal with the weighting if necessary */ if ((problem->type == NODAL) && (weight->type & EL_BLK)) { /* is this block weighted */ if (wgt >= 0) { /* check if I read an exodus file */ if (weight->type & READ_EXO) { /* check if it can be overwritten */ if (weight->ow_read) { /* check if it has been overwritten already */ if (weight->ow[node]) { weight->vertices[node] = MAX(weight->vertices[node], weight->elemblk_wgt[wgt]); } else { weight->vertices[node] = weight->elemblk_wgt[wgt]; weight->ow[node] = 1; /* read value has been overwritten */ } } } else { weight->vertices[node] = MAX(weight->vertices[node], weight->elemblk_wgt[wgt]); } } else { /* now check if this weight has been initialized */ if (weight->vertices[node] < 1) weight->vertices[node] = 1; } } } gelem_cnt++; } } else { // No weights... for (int64_t cnt2=0; cnt2 < el_blk_cnts[cnt]; cnt2++) { mesh->elem_type[gelem_cnt] = blk_elem_type; for (int64_t cnt3=0; cnt3 < nodes_per_elem; cnt3++) { INT node = blk_connect[cnt2*nodes_per_elem + cnt3] - 1; assert(node >= 0); mesh->connect[gelem_cnt][cnt3] = node; } gelem_cnt++; } } /* Free up memory */ free(blk_connect); } /* End "for(cnt=0; cnt < mesh->num_el_blks; cnt++)" */ /* if there is a group designator, then parse it here */ if (problem->groups != NULL) { if (!parse_groups(&el_blk_ids[0], &el_blk_cnts[0], mesh, problem)) { Gen_Error(0, "fatal: unable to parse group designator"); ex_close(exoid); return 0; } } else problem->num_groups = 1; /* there is always one group */ /* Close the ExodusII file */ if(ex_close(exoid) < 0) Gen_Error(0, "warning: failed to close ExodusII mesh file"); return 1; } /*---------------------------End read_mesh()-------------------------------*/
int main (int argc, char **argv) { int exoid, num_dim, num_nodes, num_elem, num_elem_blk; int num_elem_in_block[10], num_nodes_per_elem[10]; int num_face_in_sset[10], num_nodes_in_nset[10]; int num_node_sets, num_side_sets, error; int i, j, k, m, *elem_map, *connect; int node_list[100],elem_list[100],side_list[100]; int ebids[10], ssids[10], nsids[10]; int num_qa_rec, num_info; int num_glo_vars, num_nod_vars, num_ele_vars, num_sset_vars, num_nset_vars; int *truth_tab; int whole_time_step, num_time_steps; int CPU_word_size,IO_word_size; int prop_array[2]; float *glob_var_vals, *nodal_var_vals, *elem_var_vals; float *sset_var_vals, *nset_var_vals; float time_value; float x[100], y[100], z[100]; float attrib[1], dist_fact[100]; char *coord_names[3], *qa_record[2][4], *info[3], *variable_names[3]; char *block_names[10], *nset_names[10], *sset_names[10]; char *prop_names[2], *attrib_names[2]; char *title = "This is a test"; ex_opts (EX_VERBOSE | EX_ABORT ); /* Specify compute and i/o word size */ CPU_word_size = 0; /* sizeof(float) */ IO_word_size = 4; /* (4 bytes) */ /* create EXODUS II file */ exoid = ex_create ("test.exo", /* filename path */ EX_CLOBBER, /* create mode */ &CPU_word_size, /* CPU float word size in bytes */ &IO_word_size); /* I/O float word size in bytes */ printf ("after ex_create for test.exo, exoid = %d\n", exoid); printf (" cpu word size: %d io word size: %d\n",CPU_word_size,IO_word_size); ex_set_option(exoid, EX_OPT_MAX_NAME_LENGTH, 127); /* Using long names */ /* initialize file with parameters */ num_dim = 3; num_nodes = 33; num_elem = 7; num_elem_blk = 7; num_node_sets = 2; num_side_sets = 5; error = ex_put_init (exoid, title, num_dim, num_nodes, num_elem, num_elem_blk, num_node_sets, num_side_sets); printf ("after ex_put_init, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } /* write nodal coordinates values and names to database */ /* Quad #1 */ x[0] = 0.0; y[0] = 0.0; z[0] = 0.0; x[1] = 1.0; y[1] = 0.0; z[1] = 0.0; x[2] = 1.0; y[2] = 1.0; z[2] = 0.0; x[3] = 0.0; y[3] = 1.0; z[3] = 0.0; /* Quad #2 */ x[4] = 1.0; y[4] = 0.0; z[4] = 0.0; x[5] = 2.0; y[5] = 0.0; z[5] = 0.0; x[6] = 2.0; y[6] = 1.0; z[6] = 0.0; x[7] = 1.0; y[7] = 1.0; z[7] = 0.0; /* Hex #1 */ x[8] = 0.0; y[8] = 0.0; z[8] = 0.0; x[9] = 10.0; y[9] = 0.0; z[9] = 0.0; x[10] = 10.0; y[10] = 0.0; z[10] =-10.0; x[11] = 1.0; y[11] = 0.0; z[11] =-10.0; x[12] = 1.0; y[12] = 10.0; z[12] = 0.0; x[13] = 10.0; y[13] = 10.0; z[13] = 0.0; x[14] = 10.0; y[14] = 10.0; z[14] =-10.0; x[15] = 1.0; y[15] = 10.0; z[15] =-10.0; /* Tetra #1 */ x[16] = 0.0; y[16] = 0.0; z[16] = 0.0; x[17] = 1.0; y[17] = 0.0; z[17] = 5.0; x[18] = 10.0; y[18] = 0.0; z[18] = 2.0; x[19] = 7.0; y[19] = 5.0; z[19] = 3.0; /* Wedge #1 */ x[20] = 3.0; y[20] = 0.0; z[20] = 6.0; x[21] = 6.0; y[21] = 0.0; z[21] = 0.0; x[22] = 0.0; y[22] = 0.0; z[22] = 0.0; x[23] = 3.0; y[23] = 2.0; z[23] = 6.0; x[24] = 6.0; y[24] = 2.0; z[24] = 2.0; x[25] = 0.0; y[25] = 2.0; z[25] = 0.0; /* Tetra #2 */ x[26] = 2.7; y[26] = 1.7; z[26] = 2.7; x[27] = 6.0; y[27] = 1.7; z[27] = 3.3; x[28] = 5.7; y[28] = 1.7; z[28] = 1.7; x[29] = 3.7; y[29] = 0.0; z[29] = 2.3; /* 3d Tri */ x[30] = 0.0; y[30] = 0.0; z[30] = 0.0; x[31] = 10.0; y[31] = 0.0; z[31] = 0.0; x[32] = 10.0; y[32] = 10.0; z[32] = 10.0; error = ex_put_coord (exoid, x, y, z); printf ("after ex_put_coord, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } /* 0 1 2 3 4 5 6 */ /* 1234567890123456789012345678901234567890123456789012345678901234 */ coord_names[0] = "X coordinate name that is padded to be longer than 32 characters"; coord_names[1] = "Y coordinate name that is padded to be longer than 32 characters"; coord_names[2] = "Z coordinate name that is padded to be longer than 32 characters"; error = ex_put_coord_names (exoid, coord_names); printf ("after ex_put_coord_names, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } /* Add nodal attributes */ error = ex_put_attr_param(exoid, EX_NODAL, 0, 2); printf ("after ex_put_attr_param, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_one_attr(exoid, EX_NODAL, 0, 1, x); if (error) { ex_close (exoid); exit(-1); } error = ex_put_one_attr(exoid, EX_NODAL, 0, 2, y); if (error) { ex_close (exoid); exit(-1); } { attrib_names[0] = "Node_attr_1"; attrib_names[1] = "Node_attr_2"; error = ex_put_attr_names (exoid, EX_NODAL, 0, attrib_names); if (error) { ex_close (exoid); exit(-1); } } /* write element order map */ elem_map = (int *) calloc(num_elem, sizeof(int)); for (i=1; i<=num_elem; i++) { elem_map[i-1] = i; } error = ex_put_map (exoid, elem_map); printf ("after ex_put_map, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } free (elem_map); /* write element block parameters */ /* 0 1 2 3 4 5 6 */ /* 1234567890123456789012345678901234567890123456789012345678901234 */ block_names[0] = "Very long name for block_1 that exceeds 32 characters"; block_names[1] = "Very long name for block_2 that exceeds 32 characters"; block_names[2] = "Very long name for block_3 that exceeds 32 characters"; block_names[3] = "Very long name for block_4 that exceeds 32 characters"; block_names[4] = "Very long name for block_5 that exceeds 32 characters"; block_names[5] = "Very long name for block_6 that exceeds 32 characters"; block_names[6] = "Very long name for block_7 that exceeds 32 characters"; num_elem_in_block[0] = 1; num_elem_in_block[1] = 1; num_elem_in_block[2] = 1; num_elem_in_block[3] = 1; num_elem_in_block[4] = 1; num_elem_in_block[5] = 1; num_elem_in_block[6] = 1; num_nodes_per_elem[0] = 4; /* elements in block #1 are 4-node quads */ num_nodes_per_elem[1] = 4; /* elements in block #2 are 4-node quads */ num_nodes_per_elem[2] = 8; /* elements in block #3 are 8-node hexes */ num_nodes_per_elem[3] = 4; /* elements in block #4 are 4-node tetras */ num_nodes_per_elem[4] = 6; /* elements in block #5 are 6-node wedges */ num_nodes_per_elem[5] = 8; /* elements in block #6 are 8-node tetras */ num_nodes_per_elem[6] = 3; /* elements in block #7 are 3-node tris */ ebids[0] = 10; ebids[1] = 11; ebids[2] = 12; ebids[3] = 13; ebids[4] = 14; ebids[5] = 15; ebids[6] = 16; error = ex_put_elem_block (exoid, ebids[0], "quad", num_elem_in_block[0], num_nodes_per_elem[0], 1); printf ("after ex_put_elem_block, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_elem_block (exoid, ebids[1], "quad", num_elem_in_block[1], num_nodes_per_elem[1], 1); printf ("after ex_put_elem_block, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_elem_block (exoid, ebids[2], "hex", num_elem_in_block[2], num_nodes_per_elem[2], 1); printf ("after ex_put_elem_block, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_elem_block (exoid, ebids[3], "tetra", num_elem_in_block[3], num_nodes_per_elem[3], 1); printf ("after ex_put_elem_block, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_elem_block (exoid, ebids[4], "wedge", num_elem_in_block[4], num_nodes_per_elem[4], 1); printf ("after ex_put_elem_block, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_elem_block (exoid, ebids[5], "tetra", num_elem_in_block[5], num_nodes_per_elem[5], 1); printf ("after ex_put_elem_block, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_elem_block (exoid, ebids[6], "tri", num_elem_in_block[6], num_nodes_per_elem[6], 1); printf ("after ex_put_elem_block, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } /* Write element block names */ error = ex_put_names(exoid, EX_ELEM_BLOCK, block_names); printf ("after ex_put_names, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } /* write element block properties */ /* 0 1 2 3 4 5 6 */ /* 1234567890123456789012345678901234567890123456789012345678901234 */ prop_names[0] = "MATERIAL_PROPERTY_LONG_NAME_32CH"; prop_names[1] = "DENSITY"; error = ex_put_prop_names(exoid,EX_ELEM_BLOCK,2,prop_names); printf ("after ex_put_prop_names, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[0], prop_names[0], 10); printf ("after ex_put_prop, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[1], prop_names[0], 20); printf ("after ex_put_prop, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[2], prop_names[0], 30); printf ("after ex_put_prop, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[3], prop_names[0], 40); printf ("after ex_put_prop, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[4], prop_names[0], 50); printf ("after ex_put_prop, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[5], prop_names[0], 60); printf ("after ex_put_prop, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[6], prop_names[0], 70); printf ("after ex_put_prop, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } /* write element connectivity */ connect = (int *) calloc(8, sizeof(int)); connect[0] = 1; connect[1] = 2; connect[2] = 3; connect[3] = 4; error = ex_put_elem_conn (exoid, ebids[0], connect); printf ("after ex_put_elem_conn, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } connect[0] = 5; connect[1] = 6; connect[2] = 7; connect[3] = 8; error = ex_put_elem_conn (exoid, ebids[1], connect); printf ("after ex_put_elem_conn, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } connect[0] = 9; connect[1] = 10; connect[2] = 11; connect[3] = 12; connect[4] = 13; connect[5] = 14; connect[6] = 15; connect[7] = 16; error = ex_put_elem_conn (exoid, ebids[2], connect); printf ("after ex_put_elem_conn, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } connect[0] = 17; connect[1] = 18; connect[2] = 19; connect[3] = 20; error = ex_put_elem_conn (exoid, ebids[3], connect); printf ("after ex_put_elem_conn, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } connect[0] = 21; connect[1] = 22; connect[2] = 23; connect[3] = 24; connect[4] = 25; connect[5] = 26; error = ex_put_elem_conn (exoid, ebids[4], connect); printf ("after ex_put_elem_conn, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } connect[0] = 17; connect[1] = 18; connect[2] = 19; connect[3] = 20; connect[4] = 27; connect[5] = 28; connect[6] = 30; connect[7] = 29; error = ex_put_elem_conn (exoid, ebids[5], connect); printf ("after ex_put_elem_conn, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } connect[0] = 31; connect[1] = 32; connect[2] = 33; error = ex_put_elem_conn (exoid, ebids[6], connect); printf ("after ex_put_elem_conn, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } free (connect); /* write element block attributes */ attrib[0] = 3.14159; error = ex_put_elem_attr (exoid, ebids[0], attrib); printf ("after ex_put_elem_attr, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_elem_attr (exoid, ebids[0], attrib); printf ("after ex_put_elem_attr, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } attrib[0] = 6.14159; error = ex_put_elem_attr (exoid, ebids[1], attrib); printf ("after ex_put_elem_attr, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_elem_attr (exoid, ebids[2], attrib); printf ("after ex_put_elem_attr, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_elem_attr (exoid, ebids[3], attrib); printf ("after ex_put_elem_attr, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_elem_attr (exoid, ebids[4], attrib); printf ("after ex_put_elem_attr, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_elem_attr (exoid, ebids[5], attrib); printf ("after ex_put_elem_attr, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_elem_attr (exoid, ebids[6], attrib); printf ("after ex_put_elem_attr, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } /* 0 1 2 3 4 5 6 */ /* 1234567890123456789012345678901234567890123456789012345678901234 */ attrib_names[0] = "The name for the attribute representing the shell thickness"; for (i=0; i < 7; i++) { error = ex_put_elem_attr_names (exoid, ebids[i], attrib_names); printf ("after ex_put_elem_attr_names, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } } /* write individual node sets */ num_nodes_in_nset[0] = 5; num_nodes_in_nset[1] = 3; nsids[0] = 20; nsids[1] = 21; error = ex_put_node_set_param (exoid, nsids[0], 5, 5); printf ("after ex_put_node_set_param, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } node_list[0] = 10; node_list[1] = 11; node_list[2] = 12; node_list[3] = 13; node_list[4] = 14; dist_fact[0] = 1.0; dist_fact[1] = 2.0; dist_fact[2] = 3.0; dist_fact[3] = 4.0; dist_fact[4] = 5.0; error = ex_put_node_set (exoid, nsids[0], node_list); printf ("after ex_put_node_set, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_node_set_dist_fact (exoid, nsids[0], dist_fact); printf ("after ex_put_node_set_dist_fact, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_node_set_param (exoid, nsids[1], 3, 3); printf ("after ex_put_node_set_param, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } node_list[0] = 20; node_list[1] = 21; node_list[2] = 22; dist_fact[0] = 1.1; dist_fact[1] = 2.1; dist_fact[2] = 3.1; error = ex_put_node_set (exoid, nsids[1], node_list); printf ("after ex_put_node_set, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_node_set_dist_fact (exoid, nsids[1], dist_fact); printf ("after ex_put_node_set_dist_fact, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } /* Write node set names */ nset_names[0] = "nset_1"; nset_names[1] = "nset_2"; error = ex_put_names(exoid, EX_NODE_SET, nset_names); printf ("after ex_put_names, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_prop(exoid, EX_NODE_SET, nsids[0], "FACE", 4); printf ("after ex_put_prop, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_prop(exoid, EX_NODE_SET, nsids[1], "FACE", 5); printf ("after ex_put_prop, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } prop_array[0] = 1000; prop_array[1] = 2000; error = ex_put_prop_array(exoid, EX_NODE_SET, "VELOCITY", prop_array); printf ("after ex_put_prop_array, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } /* Add nodeset attributes */ error = ex_put_attr_param(exoid, EX_NODE_SET, nsids[0], 1); printf ("after ex_put_attr_param, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_attr(exoid, EX_NODE_SET, nsids[0], x); if (error) { ex_close (exoid); exit(-1); } { attrib_names[0] = "Nodeset_attribute"; error = ex_put_attr_names (exoid, EX_NODE_SET, nsids[0], attrib_names); if (error) { ex_close (exoid); exit(-1); } } /* write individual side sets */ num_face_in_sset[0] = 2; num_face_in_sset[1] = 2; num_face_in_sset[2] = 7; num_face_in_sset[3] = 8; num_face_in_sset[4] = 10; ssids[0] = 30; ssids[1] = 31; ssids[2] = 32; ssids[3] = 33; ssids[4] = 34; /* side set #1 - quad */ error = ex_put_side_set_param (exoid, ssids[0], 2, 4); printf ("after ex_put_side_set_param, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } elem_list[0] = 2; elem_list[1] = 2; side_list[0] = 4; side_list[1] = 2; dist_fact[0] = 30.0; dist_fact[1] = 30.1; dist_fact[2] = 30.2; dist_fact[3] = 30.3; error = ex_put_side_set (exoid, 30, elem_list, side_list); printf ("after ex_put_side_set, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_side_set_dist_fact (exoid, 30, dist_fact); printf ("after ex_put_side_set_dist_fact, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } /* side set #2 - quad, spanning 2 elements */ error = ex_put_side_set_param (exoid, 31, 2, 4); printf ("after ex_put_side_set_param, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } elem_list[0] = 1; elem_list[1] = 2; side_list[0] = 2; side_list[1] = 3; dist_fact[0] = 31.0; dist_fact[1] = 31.1; dist_fact[2] = 31.2; dist_fact[3] = 31.3; error = ex_put_side_set (exoid, 31, elem_list, side_list); printf ("after ex_put_side_set, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_side_set_dist_fact (exoid, 31, dist_fact); printf ("after ex_put_side_set_dist_fact, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } /* side set #3 - hex */ error = ex_put_side_set_param (exoid, 32, 7, 0); printf ("after ex_put_side_set_param, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } elem_list[0] = 3; elem_list[1] = 3; elem_list[2] = 3; elem_list[3] = 3; elem_list[4] = 3; elem_list[5] = 3; elem_list[6] = 3; side_list[0] = 5; side_list[1] = 3; side_list[2] = 3; side_list[3] = 2; side_list[4] = 4; side_list[5] = 1; side_list[6] = 6; error = ex_put_side_set (exoid, 32, elem_list, side_list); printf ("after ex_put_side_set, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } /* side set #4 - tetras */ error = ex_put_side_set_param (exoid, 33, 8, 0); printf ("after ex_put_side_set_param, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } elem_list[0] = 4; elem_list[1] = 4; elem_list[2] = 4; elem_list[3] = 4; elem_list[4] = 6; elem_list[5] = 6; elem_list[6] = 6; elem_list[7] = 6; side_list[0] = 1; side_list[1] = 2; side_list[2] = 3; side_list[3] = 4; side_list[4] = 1; side_list[5] = 2; side_list[6] = 3; side_list[7] = 4; error = ex_put_side_set (exoid, 33, elem_list, side_list); printf ("after ex_put_side_set, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } /* side set #5 - wedges and tris */ error = ex_put_side_set_param (exoid, 34, 10, 0); printf ("after ex_put_side_set_param, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } elem_list[0] = 5; elem_list[1] = 5; elem_list[2] = 5; elem_list[3] = 5; elem_list[4] = 5; elem_list[5] = 7; elem_list[6] = 7; elem_list[7] = 7; elem_list[8] = 7; elem_list[9] = 7; side_list[0] = 1; side_list[1] = 2; side_list[2] = 3; side_list[3] = 4; side_list[4] = 5; side_list[5] = 1; side_list[6] = 2; side_list[7] = 3; side_list[8] = 4; side_list[9] = 5; error = ex_put_side_set (exoid, 34, elem_list, side_list); printf ("after ex_put_side_set, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } /* Write side set names */ sset_names[0] = "sset_1"; sset_names[1] = "sset_2"; sset_names[2] = "sset_3"; sset_names[3] = "sset_4"; sset_names[4] = "sset_5"; error = ex_put_names(exoid, EX_SIDE_SET, sset_names); printf ("after ex_put_names, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_prop(exoid, EX_SIDE_SET, 30, "COLOR", 100); printf ("after ex_put_prop, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_prop(exoid, EX_SIDE_SET, 31, "COLOR", 101); printf ("after ex_put_prop, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } /* write QA records; test empty and just blank-filled records */ num_qa_rec = 2; qa_record[0][0] = "TESTWT"; qa_record[0][1] = "testwt"; qa_record[0][2] = "07/07/93"; qa_record[0][3] = "15:41:33"; qa_record[1][0] = ""; qa_record[1][1] = " "; qa_record[1][2] = ""; qa_record[1][3] = " "; error = ex_put_qa (exoid, num_qa_rec, qa_record); printf ("after ex_put_qa, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } /* write information records; test empty and just blank-filled records */ num_info = 3; info[0] = "This is the first information record."; info[1] = ""; info[2] = " "; error = ex_put_info (exoid, num_info, info); printf ("after ex_put_info, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } /* write results variables parameters and names */ num_glo_vars = 1; variable_names[0] = "glo_vars"; error = ex_put_variable_param (exoid, EX_GLOBAL, num_glo_vars); printf ("after ex_put_variable_param, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_variable_names (exoid, EX_GLOBAL, num_glo_vars, variable_names); printf ("after ex_put_variable_names, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } num_nod_vars = 2; /* 0 1 2 3 4 5 6 */ /* 1234567890123456789012345678901234567890123456789012345678901234 */ variable_names[0] = "node_variable_a_somewhat_long_name_0"; variable_names[1] = "node_variable_a_much_longer_name_that_is_not_too_long_name"; error = ex_put_variable_param (exoid, EX_NODAL, num_nod_vars); printf ("after ex_put_variable_param, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_variable_names (exoid, EX_NODAL, num_nod_vars, variable_names); printf ("after ex_put_variable_names, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } num_ele_vars = 3; /* 0 1 2 3 4 5 6 */ /* 1234567890123456789012345678901234567890123456789012345678901234 */ variable_names[0] = "the_stress_on_the_elements_in_this_block_that_are_active_now"; variable_names[1] = "ele_var1"; variable_names[2] = "ele_var2"; error = ex_put_variable_param (exoid, EX_ELEM_BLOCK, num_ele_vars); printf ("after ex_put_variable_param, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_variable_names (exoid, EX_ELEM_BLOCK, num_ele_vars, variable_names); printf ("after ex_put_variable_names, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } { num_nset_vars = 3; variable_names[0] = "ns_var0"; variable_names[1] = "ns_var1"; variable_names[2] = "ns_var2"; error = ex_put_variable_param (exoid, EX_NODE_SET, num_nset_vars); printf ("after ex_put_variable_param, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_variable_names (exoid, EX_NODE_SET, num_nset_vars, variable_names); printf ("after ex_put_variable_names, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } } { num_sset_vars = 3; variable_names[0] = "ss_var0"; variable_names[1] = "ss_var1"; variable_names[2] = "ss_var2"; error = ex_put_variable_param (exoid, EX_SIDE_SET, num_sset_vars); printf ("after ex_put_variable_param, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } error = ex_put_variable_names (exoid, EX_SIDE_SET, num_sset_vars, variable_names); printf ("after ex_put_variable_names, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } } /* write element variable truth table */ truth_tab = (int *) calloc ((num_elem_blk*num_ele_vars), sizeof(int)); k = 0; for (i=0; i<num_elem_blk; i++) { for (j=0; j<num_ele_vars; j++) { truth_tab[k++] = 1; } } error = ex_put_elem_var_tab (exoid, num_elem_blk, num_ele_vars, truth_tab); printf ("after ex_put_elem_var_tab, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } free (truth_tab); /* for each time step, write the analysis results; * the code below fills the arrays glob_var_vals, * nodal_var_vals, and elem_var_vals with values for debugging purposes; * obviously the analysis code will populate these arrays */ whole_time_step = 1; num_time_steps = 10; glob_var_vals = (float *) calloc (num_glo_vars, CPU_word_size); nodal_var_vals = (float *) calloc (num_nodes, CPU_word_size); elem_var_vals = (float *) calloc (4, CPU_word_size); sset_var_vals = (float *) calloc (10, CPU_word_size); nset_var_vals = (float *) calloc (10, CPU_word_size); for (i=0; i<num_time_steps; i++) { time_value = (float)(i+1)/100.; /* write time value */ error = ex_put_time (exoid, whole_time_step, &time_value); printf ("after ex_put_time, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } /* write global variables */ for (j=0; j<num_glo_vars; j++) { glob_var_vals[j] = (float)(j+2) * time_value; } error = ex_put_glob_vars (exoid, whole_time_step, num_glo_vars, glob_var_vals); printf ("after ex_put_glob_vars, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } /* write nodal variables */ for (k=1; k<=num_nod_vars; k++) { for (j=0; j<num_nodes; j++) { nodal_var_vals[j] = (float)k + ((float)(j+1) * time_value); } error = ex_put_nodal_var (exoid, whole_time_step, k, num_nodes, nodal_var_vals); printf ("after ex_put_nodal_var, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } } /* write element variables */ for (k=1; k<=num_ele_vars; k++) { for (j=0; j<num_elem_blk; j++) { for (m=0; m<num_elem_in_block[j]; m++) { elem_var_vals[m] = (float)(k+1) + (float)(j+2) + ((float)(m+1)*time_value); /* printf("elem_var_vals[%d]: %f\n",m,elem_var_vals[m]); */ } error = ex_put_elem_var (exoid, whole_time_step, k, ebids[j], num_elem_in_block[j], elem_var_vals); printf ("after ex_put_elem_var, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } } } /* write sideset variables */ for (k=1; k<=num_sset_vars; k++) { for (j=0; j<num_side_sets; j++) { for (m=0; m<num_face_in_sset[j]; m++) { sset_var_vals[m] = (float)(k+2) + (float)(j+3) + ((float)(m+1)*time_value); /* printf("sset_var_vals[%d]: %f\n",m,sset_var_vals[m]); */ } error = ex_put_sset_var (exoid, whole_time_step, k, ssids[j], num_face_in_sset[j], sset_var_vals); printf ("after ex_put_sset_var, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } } } /* write nodeset variables */ for (k=1; k<=num_nset_vars; k++) { for (j=0; j<num_node_sets; j++) { for (m=0; m<num_nodes_in_nset[j]; m++) { nset_var_vals[m] = (float)(k+3) + (float)(j+4) + ((float)(m+1)*time_value); /* printf("nset_var_vals[%d]: %f\n",m,nset_var_vals[m]); */ } error = ex_put_nset_var (exoid, whole_time_step, k, nsids[j], num_nodes_in_nset[j], nset_var_vals); printf ("after ex_put_nset_var, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } } } whole_time_step++; /* update the data file; this should be done at the end of every time step * to ensure that no data is lost if the analysis dies */ error = ex_update (exoid); printf ("after ex_update, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } } free(glob_var_vals); free(nodal_var_vals); free(elem_var_vals); free(sset_var_vals); free(nset_var_vals); /* close the EXODUS files */ error = ex_close (exoid); printf ("after ex_close, error = %d\n", error); if (error) { ex_close (exoid); exit(-1); } return 0; }
int read_exo_weights(Problem_Description* prob, Weight_Description<INT>* weight) { int exoid, cpu_ws=0, io_ws=0; int neblks; float version, minval = 1.0f; char elem_type[MAX_STR_LENGTH+1]; char ctemp[1024]; /*---------------------------Execution Begins--------------------------------*/ /* Open the ExodusII file containing the weights */ int mode = EX_READ | prob->int64api; if((exoid=ex_open(weight->exo_filename.c_str(), mode, &cpu_ws, &io_ws, &version)) < 0) { sprintf(ctemp, "fatal: could not open ExodusII file %s", weight->exo_filename.c_str()); Gen_Error(0, ctemp); return 0; } std::vector<float> values(weight->nvals); if(prob->type == NODAL) { size_t tmp_nodes = ex_inquire_int(exoid, EX_INQ_NODES); /* check to make sure the sizes agree */ if ((size_t)weight->nvals != tmp_nodes) { Gen_Error(0, "fatal: different number of nodes in mesh and weight files"); ex_close(exoid); return 0; } weight->ow.resize(weight->nvals); /* Read in the nodal values */ if(ex_get_nodal_var(exoid, weight->exo_tindx, weight->exo_vindx, weight->nvals, TOPTR(values)) < 0) { Gen_Error(0, "fatal: unable to read nodal values"); ex_close(exoid); return 0; } } else { size_t tmp_elem = ex_inquire_int(exoid, EX_INQ_ELEM); /* check to make sure the sizes agree */ if ((size_t)weight->nvals != tmp_elem) { Gen_Error(0, "fatal: different number of elems in mesh and weight files"); ex_close(exoid); return 0; } /* Get the number of element blocks */ neblks = ex_inquire_int(exoid, EX_INQ_ELEM_BLK); std::vector<INT> eblk_ids(neblks); std::vector<INT> eblk_ecnts(neblks); if(ex_get_ids(exoid, EX_ELEM_BLOCK, &eblk_ids[0]) < 0) { Gen_Error(0, "fatal: unable to get element block IDs"); ex_close(exoid); return 0; } /* Get the count of elements in each element block */ for(int cnt=0; cnt < neblks; cnt++) { INT dum1, dum2; if(ex_get_elem_block(exoid, eblk_ids[cnt], elem_type, &(eblk_ecnts[cnt]), &dum1, &dum2) < 0) { Gen_Error(0, "fatal: unable to get element block"); ex_close(exoid); return 0; } } /* Get the element variables */ size_t offset = 0; for(int cnt=0; cnt < neblks; cnt++) { if(ex_get_elem_var(exoid, weight->exo_tindx, weight->exo_vindx, eblk_ids[cnt], eblk_ecnts[cnt], &(values[offset])) < 0) { Gen_Error(0, "fatal: unable to get element variable"); ex_close(exoid); return 0; } offset += eblk_ecnts[cnt]; } } /* Close the ExodusII weighting file */ if(ex_close(exoid) < 0) { sprintf(ctemp, "warning: failed to close ExodusII file %s", weight->exo_filename.c_str()); Gen_Error(0, ctemp); } /* now I need to translate the values to positive integers */ /* first find the minimum value */ minval = *std::min_element(values.begin(), values.end()); /* now translate the values to be greater than 1 and convert to ints */ for (int cnt=0; cnt < weight->nvals; cnt++) { values[cnt] += 1.0 - minval; weight->vertices[cnt] = roundfloat(values[cnt]); } return 1; } /*------------------------End read_exo_weights()----------------------*/
int main (int argc, char **argv) { int exoid, num_dim, num_nodes, num_elem, num_elem_blk; int num_elem_in_block[10], num_nodes_per_elem[10]; int num_node_sets, num_sides, num_side_sets, error; int i, j, k, m, *elem_map, *connect; int node_list[100],elem_list[100],side_list[100]; int ebids[10], ids[10]; int num_sides_per_set[10], num_nodes_per_set[10], num_elem_per_set[10]; int num_df_per_set[10]; int df_ind[10], node_ind[10], elem_ind[10], side_ind[10]; int num_qa_rec, num_info; int num_glo_vars, num_nod_vars, num_ele_vars; int *truth_tab; int whole_time_step, num_time_steps; int ndims, nvars, ngatts, recdim; int CPU_word_size,IO_word_size; int prop_array[2]; float *glob_var_vals, *nodal_var_vals, *elem_var_vals; float time_value; float *x, *y, *z, *dummy; float attrib[1], dist_fact[100]; char *coord_names[3], *qa_record[2][4], *info[3], *var_names[3]; char tmpstr[80]; char *prop_names[2]; ex_opts (EX_VERBOSE | EX_ABORT); dummy = 0; /* assign this so the Cray compiler doesn't complain */ /* Specify compute and i/o word size */ CPU_word_size = 0; /* sizeof(float) */ IO_word_size = 4; /* (4 bytes) */ /* create EXODUS II file */ exoid = ex_create ("test.exo", /* filename path */ EX_CLOBBER, /* create mode */ &CPU_word_size, /* CPU float word size in bytes */ &IO_word_size); /* I/O float word size in bytes */ printf ("after ex_create for test.exo, exoid = %d\n", exoid); printf (" cpu word size: %d io word size: %d\n",CPU_word_size,IO_word_size); /* initialize file with parameters */ num_dim = 3; num_nodes = BIG; num_elem = BIG; num_elem_blk = 5; num_node_sets = 2; num_side_sets = 5; error = ex_put_init (exoid, "This is a test", num_dim, num_nodes, num_elem, num_elem_blk, num_node_sets, num_side_sets); printf ("after ex_put_init, error = %d\n", error); /* write nodal coordinates values and names to database */ if (!(x = (float *) calloc(BIG, sizeof(float)))) { printf ("couldn't allocate memory for x node array%d\n"); exit(1); } if (!(y = (float *) calloc(BIG, sizeof(float)))) { printf ("couldn't allocate memory for y node array%d\n"); exit(1); } if (!(z = (float *) calloc(BIG, sizeof(float)))) { printf ("couldn't allocate memory for z node array%d\n"); exit(1); } for (i=0; i<num_nodes; i++) { /* dummy up the coordinate space */ x[i]=i; y[i]=i+.1; z[i]=i+.2; } error = ex_put_coord (exoid, x, y, z); printf ("after ex_put_coord, error = %d\n", error); coord_names[0] = "xcoor"; coord_names[1] = "ycoor"; coord_names[2] = "zcoor"; error = ex_put_coord_names (exoid, coord_names); printf ("after ex_put_coord_names, error = %d\n", error); /* write element order map */ elem_map = (int *) calloc(num_elem, sizeof(int)); for (i=1; i<=num_elem; i++) { elem_map[i-1] = i; } error = ex_put_map (exoid, elem_map); printf ("after ex_put_map, error = %d\n", error); free (elem_map); /* write element block parameters */ num_elem_in_block[0] = 1; num_elem_in_block[1] = 1; num_elem_in_block[2] = 1; num_elem_in_block[3] = 1; num_elem_in_block[4] = 1; num_nodes_per_elem[0] = 4; /* elements in block #1 are 4-node quads */ num_nodes_per_elem[1] = 4; /* elements in block #2 are 4-node quads */ num_nodes_per_elem[2] = 8; /* elements in block #3 are 8-node hexes */ num_nodes_per_elem[3] = 4; /* elements in block #3 are 4-node tetras */ num_nodes_per_elem[4] = 6; /* elements in block #3 are 6-node wedges */ ebids[0] = 10; ebids[1] = 11; ebids[2] = 12; ebids[3] = 13; ebids[4] = 14; error = ex_put_elem_block (exoid, ebids[0], "quad", num_elem_in_block[0], num_nodes_per_elem[0], 1); printf ("after ex_put_elem_block, error = %d\n", error); error = ex_put_elem_block (exoid, ebids[1], "quad", num_elem_in_block[1], num_nodes_per_elem[1], 1); printf ("after ex_put_elem_block, error = %d\n", error); error = ex_put_elem_block (exoid, ebids[2], "hex", num_elem_in_block[2], num_nodes_per_elem[2], 1); printf ("after ex_put_elem_block, error = %d\n", error); error = ex_put_elem_block (exoid, ebids[3], "tetra", num_elem_in_block[3], num_nodes_per_elem[3], 1); printf ("after ex_put_elem_block, error = %d\n", error); error = ex_put_elem_block (exoid, ebids[4], "wedge", num_elem_in_block[4], num_nodes_per_elem[4], 1); printf ("after ex_put_elem_block, error = %d\n", error); /* write element block properties */ prop_names[0] = "MATL"; prop_names[1] = "DENSITY"; error = ex_put_prop_names(exoid,EX_ELEM_BLOCK,2,prop_names); printf ("after ex_put_prop_names, error = %d\n", error); error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[0], "MATL", 10); printf ("after ex_put_prop, error = %d\n", error); error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[1], "MATL", 20); printf ("after ex_put_prop, error = %d\n", error); error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[2], "MATL", 30); printf ("after ex_put_prop, error = %d\n", error); error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[3], "MATL", 40); printf ("after ex_put_prop, error = %d\n", error); error = ex_put_prop(exoid, EX_ELEM_BLOCK, ebids[4], "MATL", 50); printf ("after ex_put_prop, error = %d\n", error); /* write element connectivity */ connect = (int *) calloc(8, sizeof(int)); connect[0] = 1; connect[1] = 2; connect[2] = 3; connect[3] = 4; error = ex_put_elem_conn (exoid, ebids[0], connect); printf ("after ex_put_elem_conn, error = %d\n", error); connect[0] = 5; connect[1] = 6; connect[2] = 7; connect[3] = 8; error = ex_put_elem_conn (exoid, ebids[1], connect); printf ("after ex_put_elem_conn, error = %d\n", error); connect[0] = 9; connect[1] = 10; connect[2] = 11; connect[3] = 12; connect[4] = 13; connect[5] = 14; connect[6] = 15; connect[7] = 16; error = ex_put_elem_conn (exoid, ebids[2], connect); printf ("after ex_put_elem_conn, error = %d\n", error); connect[0] = 17; connect[1] = 18; connect[2] = 19; connect[3] = 20; error = ex_put_elem_conn (exoid, ebids[3], connect); printf ("after ex_put_elem_conn, error = %d\n", error); connect[0] = 21; connect[1] = 22; connect[2] = 23; connect[3] = 24; connect[4] = 25; connect[5] = 26; error = ex_put_elem_conn (exoid, ebids[4], connect); printf ("after ex_put_elem_conn, error = %d\n", error); free (connect); /* write element block attributes */ attrib[0] = 3.14159; error = ex_put_elem_attr (exoid, ebids[0], attrib); printf ("after ex_put_elem_attr, error = %d\n", error); attrib[0] = 6.14159; error = ex_put_elem_attr (exoid, ebids[1], attrib); printf ("after ex_put_elem_attr, error = %d\n", error); error = ex_put_elem_attr (exoid, ebids[2], attrib); printf ("after ex_put_elem_attr, error = %d\n", error); error = ex_put_elem_attr (exoid, ebids[3], attrib); printf ("after ex_put_elem_attr, error = %d\n", error); error = ex_put_elem_attr (exoid, ebids[4], attrib); printf ("after ex_put_elem_attr, error = %d\n", error); /* write individual node sets */ error = ex_put_node_set_param (exoid, 20, 5, 5); printf ("after ex_put_node_set_param, error = %d\n", error); node_list[0] = 10; node_list[1] = 11; node_list[2] = 12; node_list[3] = 13; node_list[4] = 14; dist_fact[0] = 1.0; dist_fact[1] = 2.0; dist_fact[2] = 3.0; dist_fact[3] = 4.0; dist_fact[4] = 5.0; error = ex_put_node_set (exoid, 20, node_list); printf ("after ex_put_node_set, error = %d\n", error); error = ex_put_node_set_dist_fact (exoid, 20, dist_fact); printf ("after ex_put_node_set_dist_fact, error = %d\n", error); error = ex_put_node_set_param (exoid, 21, 3, 3); printf ("after ex_put_node_set_param, error = %d\n", error); node_list[0] = 20; node_list[1] = 21; node_list[2] = 22; dist_fact[0] = 1.1; dist_fact[1] = 2.1; dist_fact[2] = 3.1; error = ex_put_node_set (exoid, 21, node_list); printf ("after ex_put_node_set, error = %d\n", error); error = ex_put_node_set_dist_fact (exoid, 21, dist_fact); printf ("after ex_put_node_set_dist_fact, error = %d\n", error); error = ex_put_prop(exoid, EX_NODE_SET, 20, "FACE", 4); printf ("after ex_put_prop, error = %d\n", error); error = ex_put_prop(exoid, EX_NODE_SET, 21, "FACE", 5); printf ("after ex_put_prop, error = %d\n", error); prop_array[0] = 1000; prop_array[1] = 2000; error = ex_put_prop_array(exoid, EX_NODE_SET, "VELOCITY", prop_array); printf ("after ex_put_prop_array, error = %d\n", error); /* write concatenated node sets; this produces the same information as * the above code which writes individual node sets */ /* THIS SECTION IS COMMENTED OUT ids[0] = 20; ids[1] = 21; num_nodes_per_set[0] = 5; num_nodes_per_set[1] = 3; node_ind[0] = 0; node_ind[1] = 5; node_list[0] = 10; node_list[1] = 11; node_list[2] = 12; node_list[3] = 13; node_list[4] = 14; node_list[5] = 20; node_list[6] = 21; node_list[7] = 22; num_df_per_set[0] = 5; num_df_per_set[1] = 3; df_ind[0] = 0; df_ind[1] = 5; dist_fact[0] = 1.0; dist_fact[1] = 2.0; dist_fact[2] = 3.0; dist_fact[3] = 4.0; dist_fact[4] = 5.0; dist_fact[5] = 1.1; dist_fact[6] = 2.1; dist_fact[7] = 3.1; error = ex_put_concat_node_sets (exoid, ids, num_nodes_per_set, num_df_per_set, node_ind, df_ind, node_list, dist_fact); printf ("after ex_put_concat_node_sets, error = %d\n", error); error = ex_put_prop(exoid, EX_NODE_SET, 20, "FACE", 4); printf ("after ex_put_prop, error = %d\n", error); error = ex_put_prop(exoid, EX_NODE_SET, 21, "FACE", 5); printf ("after ex_put_prop, error = %d\n", error); prop_array[0] = 1000; prop_array[1] = 2000; error = ex_put_prop_array(exoid, EX_NODE_SET, "VELOCITY", prop_array); printf ("after ex_put_prop_array, error = %d\n", error); END COMMENTED OUT SECTION */ /* write individual side sets */ /* side set #1 - quad */ error = ex_put_side_set_param (exoid, 30, 2, 4); printf ("after ex_put_side_set_param, error = %d\n", error); elem_list[0] = 2; elem_list[1] = 2; side_list[0] = 4; side_list[1] = 2; dist_fact[0] = 30.0; dist_fact[1] = 30.1; dist_fact[2] = 30.2; dist_fact[3] = 30.3; error = ex_put_side_set (exoid, 30, elem_list, side_list); printf ("after ex_put_side_set, error = %d\n", error); error = ex_put_side_set_dist_fact (exoid, 30, dist_fact); printf ("after ex_put_side_set_dist_fact, error = %d\n", error); /* side set #2 - quad, spanning 2 elements */ error = ex_put_side_set_param (exoid, 31, 2, 4); printf ("after ex_put_side_set_param, error = %d\n", error); elem_list[0] = 1; elem_list[1] = 2; side_list[0] = 2; side_list[1] = 3; dist_fact[0] = 31.0; dist_fact[1] = 31.1; dist_fact[2] = 31.2; dist_fact[3] = 31.3; error = ex_put_side_set (exoid, 31, elem_list, side_list); printf ("after ex_put_side_set, error = %d\n", error); error = ex_put_side_set_dist_fact (exoid, 31, dist_fact); printf ("after ex_put_side_set_dist_fact, error = %d\n", error); /* side set #3 - hex */ error = ex_put_side_set_param (exoid, 32, 7, 0); printf ("after ex_put_side_set_param, error = %d\n", error); elem_list[0] = 3; elem_list[1] = 3; elem_list[2] = 3; elem_list[3] = 3; elem_list[4] = 3; elem_list[5] = 3; elem_list[6] = 3; side_list[0] = 5; side_list[1] = 3; side_list[2] = 3; side_list[3] = 2; side_list[4] = 4; side_list[5] = 1; side_list[6] = 6; error = ex_put_side_set (exoid, 32, elem_list, side_list); printf ("after ex_put_side_set, error = %d\n", error); /* side set #4 - tetras */ error = ex_put_side_set_param (exoid, 33, 4, 0); printf ("after ex_put_side_set_param, error = %d\n", error); elem_list[0] = 4; elem_list[1] = 4; elem_list[2] = 4; elem_list[3] = 4; side_list[0] = 1; side_list[1] = 2; side_list[2] = 3; side_list[3] = 4; error = ex_put_side_set (exoid, 33, elem_list, side_list); printf ("after ex_put_side_set, error = %d\n", error); /* side set #5 - wedges */ error = ex_put_side_set_param (exoid, 34, 5, 0); printf ("after ex_put_side_set_param, error = %d\n", error); elem_list[0] = 5; elem_list[1] = 5; elem_list[2] = 5; elem_list[3] = 5; elem_list[4] = 5; side_list[0] = 1; side_list[1] = 2; side_list[2] = 3; side_list[3] = 4; side_list[4] = 5; error = ex_put_side_set (exoid, 34, elem_list, side_list); printf ("after ex_put_side_set, error = %d\n", error); /* END COMMENTED OUT SECTION */ /* write concatenated side sets; this produces the same information as * the above code which writes individual side sets */ /* THIS SECTION IS COMMENTED OUT ids[0] = 30; ids[1] = 31; ids[2] = 32; ids[3] = 33; ids[4] = 34; node_list[0] = 8; node_list[1] = 5; node_list[2] = 6; node_list[3] = 7; node_list[4] = 2; node_list[5] = 3; node_list[6] = 7; node_list[7] = 8; node_list[8] = 9; node_list[9] = 12; node_list[10] = 11; node_list[11] = 10; node_list[12] = 11; node_list[13] = 12; node_list[14] = 16; node_list[15] = 15; node_list[16] = 16; node_list[17] = 15; node_list[18] = 11; node_list[19] = 12; node_list[20] = 10; node_list[21] = 11; node_list[22] = 15; node_list[23] = 14; node_list[24] = 13; node_list[25] = 16; node_list[26] = 12; node_list[27] = 9; node_list[28] = 14; node_list[29] = 13; node_list[30] = 9; node_list[31] = 10; node_list[32] = 16; node_list[33] = 13; node_list[34] = 14; node_list[35] = 15; node_list[36] = 17; node_list[37] = 18; node_list[38] = 20; node_list[39] = 18; node_list[40] = 19; node_list[41] = 20; node_list[42] = 20; node_list[43] = 19; node_list[44] = 17; node_list[45] = 19; node_list[46] = 18; node_list[47] = 17; node_list[48] = 25; node_list[49] = 24; node_list[50] = 21; node_list[51] = 22; node_list[52] = 26; node_list[53] = 25; node_list[54] = 22; node_list[55] = 23; node_list[56] = 26; node_list[57] = 23; node_list[58] = 21; node_list[59] = 24; node_list[60] = 23; node_list[61] = 22; node_list[62] = 21; node_list[63] = 24; node_list[64] = 25; node_list[65] = 26; node_ind[0] = 0; node_ind[1] = 4; node_ind[2] = 8; node_ind[3] = 36; node_ind[4] = 47; num_elem_per_set[0] = 2; num_elem_per_set[1] = 2; num_elem_per_set[2] = 7; num_elem_per_set[3] = 4; num_elem_per_set[4] = 5; num_nodes_per_set[0] = 4; num_nodes_per_set[1] = 4; num_nodes_per_set[2] = 28; num_nodes_per_set[3] = 12; num_nodes_per_set[4] = 18; elem_ind[0] = 0; elem_ind[1] = 2; elem_ind[2] = 4; elem_ind[3] = 11; elem_ind[4] = 15; elem_list[0] = 2; elem_list[1] = 2; elem_list[2] = 1; elem_list[3] = 2; elem_list[4] = 3; elem_list[5] = 3; elem_list[6] = 3; elem_list[7] = 3; elem_list[8] = 3; elem_list[9] = 3; elem_list[10] = 3; elem_list[11] = 4; elem_list[12] = 4; elem_list[13] = 4; elem_list[14] = 4; elem_list[15] = 5; elem_list[16] = 5; elem_list[17] = 5; elem_list[18] = 5; elem_list[19] = 5; error = ex_cvt_nodes_to_sides(exoid, num_elem_per_set, num_nodes_per_set, elem_ind, node_ind, elem_list, node_list, side_list); printf ("after ex_cvt_nodes_to_sides, error = %d\n", error); num_df_per_set[0] = 4; num_df_per_set[1] = 4; num_df_per_set[2] = 0; num_df_per_set[3] = 0; num_df_per_set[4] = 0; df_ind[0] = 0; df_ind[1] = 4; dist_fact[0] = 30.0; dist_fact[1] = 30.1; dist_fact[2] = 30.2; dist_fact[3] = 30.3; dist_fact[4] = 31.0; dist_fact[5] = 31.1; dist_fact[6] = 31.2; dist_fact[7] = 31.3; error = ex_put_concat_side_sets (exoid, ids, num_elem_per_set, num_df_per_set, elem_ind, df_ind, elem_list, side_list, dist_fact); printf ("after ex_put_concat_side_sets, error = %d\n", error); /* END COMMENTED OUT SECTION */ error = ex_put_prop(exoid, EX_SIDE_SET, 30, "COLOR", 100); printf ("after ex_put_prop, error = %d\n", error); error = ex_put_prop(exoid, EX_SIDE_SET, 31, "COLOR", 101); printf ("after ex_put_prop, error = %d\n", error); /* write QA records */ num_qa_rec = 2; qa_record[0][0] = "TESTWT"; qa_record[0][1] = "testwt"; qa_record[0][2] = "07/07/93"; qa_record[0][3] = "15:41:33"; qa_record[1][0] = "FASTQ"; qa_record[1][1] = "fastq"; qa_record[1][2] = "07/07/93"; qa_record[1][3] = "16:41:33"; error = ex_put_qa (exoid, num_qa_rec, qa_record); printf ("after ex_put_qa, error = %d\n", error); /* write information records */ num_info = 3; info[0] = "This is the first information record."; info[1] = "This is the second information record."; info[2] = "This is the third information record."; error = ex_put_info (exoid, num_info, info); printf ("after ex_put_info, error = %d\n", error); /* write results variables parameters and names */ num_glo_vars = 1; var_names[0] = "glo_vars"; error = ex_put_var_param (exoid, "g", num_glo_vars); printf ("after ex_put_var_param, error = %d\n", error); error = ex_put_var_names (exoid, "g", num_glo_vars, var_names); printf ("after ex_put_var_names, error = %d\n", error); num_nod_vars = 2; var_names[0] = "nod_var0"; var_names[1] = "nod_var1"; error = ex_put_var_param (exoid, "n", num_nod_vars); printf ("after ex_put_var_param, error = %d\n", error); error = ex_put_var_names (exoid, "n", num_nod_vars, var_names); printf ("after ex_put_var_names, error = %d\n", error); num_ele_vars = 3; var_names[0] = "ele_var0"; var_names[1] = "ele_var1"; var_names[2] = "ele_var2"; error = ex_put_var_param (exoid, "e", num_ele_vars); printf ("after ex_put_var_param, error = %d\n", error); error = ex_put_var_names (exoid, "e", num_ele_vars, var_names); printf ("after ex_put_var_names, error = %d\n", error); /* write element variable truth table */ truth_tab = (int *) calloc ((num_elem_blk*num_ele_vars), sizeof(int)); k = 0; for (i=0; i<num_elem_blk; i++) { for (j=0; j<num_ele_vars; j++) { truth_tab[k++] = 1; } } error = ex_put_elem_var_tab (exoid, num_elem_blk, num_ele_vars, truth_tab); printf ("after ex_put_elem_var_tab, error = %d\n", error); free (truth_tab); /* for each time step, write the analysis results; * the code below fills the arrays glob_var_vals, * nodal_var_vals, and elem_var_vals with values for debugging purposes; * obviously the analysis code will populate these arrays */ whole_time_step = 1; num_time_steps = 10; glob_var_vals = (float *) calloc (num_glo_vars, CPU_word_size); nodal_var_vals = (float *) calloc (num_nodes, CPU_word_size); elem_var_vals = (float *) calloc (4, CPU_word_size); for (i=0; i<num_time_steps; i++) { time_value = (float)(i+1)/100.; /* write time value */ error = ex_put_time (exoid, whole_time_step, &time_value); printf ("after ex_put_time, error = %d\n", error); /* write global variables */ for (j=0; j<num_glo_vars; j++) { glob_var_vals[j] = (float)(j+2) * time_value; } error = ex_put_glob_vars (exoid, whole_time_step, num_glo_vars, glob_var_vals); printf ("after ex_put_glob_vars, error = %d\n", error); /* write nodal variables */ for (k=1; k<=num_nod_vars; k++) { for (j=0; j<num_nodes; j++) { nodal_var_vals[j] = (float)k + ((float)(j+1) * time_value); } error = ex_put_nodal_var (exoid, whole_time_step, k, num_nodes, nodal_var_vals); printf ("after ex_put_nodal_var, error = %d\n", error); } /* write element variables */ for (k=1; k<=num_ele_vars; k++) { for (j=0; j<num_elem_blk; j++) { for (m=0; m<num_elem_in_block[j]; m++) { elem_var_vals[m] = (float)(k+1) + (float)(j+2) + ((float)(m+1)*time_value); /* printf("elem_var_vals[%d]: %f\n",m,elem_var_vals[m]); */ } error = ex_put_elem_var (exoid, whole_time_step, k, ebids[j], num_elem_in_block[j], elem_var_vals); printf ("after ex_put_elem_var, error = %d\n", error); } } whole_time_step++; /* update the data file; this should be done at the end of every time step * to ensure that no data is lost if the analysis dies */ error = ex_update (exoid); printf ("after ex_update, error = %d\n", error); } free(glob_var_vals); free(nodal_var_vals); free(elem_var_vals); /* close the EXODUS files */ error = ex_close (exoid); printf ("after ex_close, error = %d\n", error); return 0; }
int main (int argc, char *argv[]) { char *str,**str2,*(*qa_records)[4],*line, *oname, *dot, *filename; const char* ext=EXT; int i,j,k,n,n1,n2,cpu_word_size,io_word_size,exo_file,err, num_axes,num_nodes,num_elements,num_blocks, num_side_sets,num_node_sets,num_time_steps, num_qa_lines,num_info_lines,num_global_vars, num_nodal_vars,num_element_vars,num_nodeset_vars, num_sideset_vars, *ids,*iscr,*num_elem_in_block,*junk, *elem_list,*side_list, *nsssides,*nssdfac, *nnsnodes,*nnsdfac, nstr2, has_ss_dfac; float exo_version; double *scr,*x,*y,*z; oname=0; /* process arguments */ for (j=1; j< argc; j++){ if ( strcmp(argv[j],"-t")==0){ /* write text file (*.m) */ del_arg(&argc,argv,j); textfile=1; j--; continue; } if ( strcmp(argv[j],"-o")==0){ /* specify output file name */ del_arg(&argc,argv,j); if ( argv[j] ){ oname=(char*)calloc(strlen(argv[j])+10,sizeof(char)); strcpy(oname,argv[j]); del_arg(&argc,argv,j); printf("output file: %s\n",oname); } else { fprintf(stderr,"Invalid output file specification.\n"); return 2; } j--; continue; } } /* QA Info */ printf("%s: %s, %s\n", qainfo[0], qainfo[2], qainfo[1]); /* usage message*/ if(argc != 2){ printf("%s [options] exodus_file_name.\n",argv[0]); printf(" the exodus_file_name is required (exodusII only).\n"); printf(" Options:\n"); printf(" -t write a text (.m) file rather than a binary .mat\n"); printf(" -o output file name (rather than auto generate)\n"); printf(" ** note **\n"); printf("Binary files are written by default on all platforms with"); printf(" available libraries.\n"); exit(1); } /* open output file */ if ( textfile ) ext=".m"; if ( !oname ){ filename = (char*)malloc( strlen(argv[1])+10); strcpy(filename,argv[1]); dot=strrchr(filename,'.'); if ( dot ) *dot=0; strcat(filename,ext); } else { filename=oname; } if ( textfile ){ m_file = fopen(filename,"w"); if (!m_file ){ fprintf(stderr,"Unable to open %s\n",filename); exit(1); } } else { mat_file = Mat_CreateVer(filename, NULL, MAT_FT_MAT5); if (mat_file == NULL) { fprintf(stderr,"Unable to create matlab file %s\n",filename); exit(1); } } /* word sizes */ cpu_word_size=sizeof(double); io_word_size=0; /* open exodus file */ exo_file=ex_open(argv[1],EX_READ,&cpu_word_size,&io_word_size,&exo_version); if (exo_file < 0){ printf("error opening %s\n",argv[1]); exit(1); } /* print */ fprintf(stderr,"translating %s to %s ...\n",argv[1],filename); /* read database paramters */ line=(char *) calloc ((MAX_LINE_LENGTH+1),sizeof(char)); err = ex_get_init(exo_file,line, &num_axes,&num_nodes,&num_elements,&num_blocks, &num_node_sets,&num_side_sets); num_qa_lines = ex_inquire_int(exo_file,EX_INQ_QA); num_info_lines = ex_inquire_int(exo_file,EX_INQ_INFO); num_time_steps = ex_inquire_int(exo_file,EX_INQ_TIME); err=ex_get_variable_param(exo_file,EX_GLOBAL,&num_global_vars); err=ex_get_variable_param(exo_file,EX_NODAL,&num_nodal_vars); err=ex_get_variable_param(exo_file,EX_ELEM_BLOCK,&num_element_vars); err=ex_get_variable_param(exo_file,EX_NODE_SET,&num_nodeset_vars); err=ex_get_variable_param(exo_file,EX_SIDE_SET,&num_sideset_vars); /* export paramters */ PutInt("naxes", 1, 1,&num_axes); PutInt("nnodes", 1, 1,&num_nodes); PutInt("nelems", 1, 1,&num_elements); PutInt("nblks", 1, 1,&num_blocks); PutInt("nnsets", 1, 1,&num_node_sets); PutInt("nssets", 1, 1,&num_side_sets); PutInt("nsteps", 1, 1,&num_time_steps); PutInt("ngvars", 1, 1,&num_global_vars); PutInt("nnvars", 1, 1,&num_nodal_vars); PutInt("nevars", 1, 1,&num_element_vars); PutInt("nnsvars", 1, 1,&num_nodeset_vars); PutInt("nssvars", 1, 1,&num_sideset_vars); /* allocate -char- scratch space*/ n = num_info_lines; n = (n > num_global_vars) ? n : num_global_vars; n = (n > num_nodal_vars) ? n : num_nodal_vars; n = (n > num_element_vars) ? n : num_element_vars; n = (n > num_blocks) ? n : num_blocks; nstr2 = n; str2= (char **) calloc (n,sizeof(char *)); for (i=0;i<nstr2;i++) str2[i]=(char *) calloc ((MAX_LINE_LENGTH+1),sizeof(char)); str= (char *) calloc ((MAX_LINE_LENGTH+1)*n,sizeof(char)); /* title */ PutStr("Title",line); #if 0 /* QA records */ if (num_qa_lines > 0 ){ qa_records =(char *(*)[4]) calloc (num_qa_lines*4,sizeof(char **)); for (i=0;i<num_qa_lines;i++) for (j=0;j<4;j++) qa_records[i][j]=(char *) calloc ((MAX_STR_LENGTH+1),sizeof(char)); err=ex_get_qa(exo_file,qa_records); str[0]='\0'; for (i=0;i<num_qa_lines;i++){ for (j=0;j<4;j++) sprintf(str+strlen(str),"%s ",qa_records[i][j]); strcat(str,"\n"); } for (i=0;i<num_qa_lines;i++){ for (j=0;j<4;j++) free(qa_records[i][j]); } free(qa_records); } /* information records */ if (num_info_lines > 0 ){ err = ex_get_info(exo_file,str2); str[0]='\0'; for (i=0;i<num_info_lines;i++) sprintf(str+strlen(str),"%s\n",str2[i]); PutStr("info",str); str[0]='\0'; for (i=0;i<num_info_lines;i++) if (strncmp(str2[i],"cavi",4)==0) sprintf(str+strlen(str),"%s\n",str2[i]); PutStr("cvxp",str); } #endif /* nodal coordinates */ x = (double *) calloc(num_nodes,sizeof(double)); y = (double *) calloc(num_nodes,sizeof(double)); if (num_axes == 3) z = (double *) calloc(num_nodes,sizeof(double)); else z = NULL; err = ex_get_coord(exo_file,x,y,z); PutDbl("x0", num_nodes, 1, x); PutDbl("y0", num_nodes, 1, y); free(x); free(y); if (num_axes == 3){ PutDbl("z0",num_nodes,1, z); free(z); } /* side sets */ if(num_side_sets > 0){ ids=(int *) calloc(num_side_sets,sizeof(int)); err = ex_get_ids(exo_file,EX_SIDE_SET,ids); PutInt( "ssids",num_side_sets, 1,ids); nsssides = (int *) calloc(num_side_sets,sizeof(int)); /*dgriffi */ nssdfac = (int *) calloc(num_side_sets,sizeof(int)); /*dgriffi */ for (i=0;i<num_side_sets;i++){ err = ex_get_set_param(exo_file,EX_SIDE_SET, ids[i],&n1,&n2); nsssides[i]=n1; /* dgriffi */ nssdfac[i]=n2; /* dgriffi */ /* * the following provision is from Version 1.6 when there are no * distribution factors in exodus file */ has_ss_dfac = (n2 != 0); if(n2==0 || n1==n2){ printf(" WARNING: Exodus II file does not contain distribution factors.\n"); /* n1=number of faces, n2=number of df */ /* using distribution factors to determine number of nodes in the sideset causes a lot grief since some codes do not output distribution factors if they are all equal to 1. mkbhard: I am using the function call below to figure out the total number of nodes in this sideset. Some redundancy exists, but it works for now */ junk = (int*) calloc(n1,sizeof(int)); err = ex_get_side_set_node_count(exo_file,ids[i],junk); n2=0; /* n2 will be equal to the total number of nodes in the sideset */ for (j=0;j<n1;j++) n2+=junk[j]; free(junk); } iscr = (int *) calloc(n1+n2,sizeof(int)); err = ex_get_side_set_node_list(exo_file,ids[i],iscr,iscr+n1); /* number-of-nodes-per-side list */ sprintf(str,"ssnum%02d",i+1); PutInt(str,n1,1,iscr); /* nodes list */ sprintf(str,"ssnod%02d",i+1); PutInt(str,n2,1,iscr+n1); free(iscr); /* distribution-factors list */ scr = (double *) calloc (n2,sizeof(double)); if (has_ss_dfac) { ex_get_side_set_dist_fact(exo_file,ids[i],scr); } else { for (j=0; j<n2; j++) { scr[j] = 1.0; } } sprintf(str,"ssfac%02d",i+1); PutDbl(str,n2,1,scr); free(scr); /* element and side list for side sets (dgriffi) */ elem_list = (int *) calloc(n1, sizeof(int)); side_list = (int *) calloc(n1, sizeof(int)); err = ex_get_set(exo_file,EX_SIDE_SET,ids[i],elem_list,side_list); sprintf(str,"ssside%02d",i+1); PutInt(str,n1,1,side_list); sprintf(str,"sselem%02d",i+1); PutInt(str,n1,1,elem_list); free(elem_list); free(side_list); } /* Store # sides and # dis. factors per side set (dgriffi) */ PutInt("nsssides",num_side_sets,1,nsssides); PutInt("nssdfac",num_side_sets,1,nssdfac); free(ids); free(nsssides); free(nssdfac); } /* node sets (section by dgriffi) */ if(num_node_sets > 0){ ids=(int *) calloc(num_node_sets,sizeof(int)); err = ex_get_ids(exo_file,EX_NODE_SET, ids); PutInt( "nsids",num_node_sets, 1,ids); nnsnodes = (int *) calloc(num_node_sets,sizeof(int)); nnsdfac = (int *) calloc(num_node_sets,sizeof(int)); for (i=0;i<num_node_sets;i++){ err = ex_get_set_param(exo_file,EX_NODE_SET,ids[i],&n1,&n2); iscr = (int *) calloc(n1,sizeof(int)); err = ex_get_node_set(exo_file,ids[i],iscr); /* nodes list */ sprintf(str,"nsnod%02d",i+1); PutInt(str,n1,1,iscr); free(iscr); /* distribution-factors list */ scr = (double *) calloc (n2,sizeof(double)); ex_get_node_set_dist_fact(exo_file,ids[i],scr); sprintf(str,"nsfac%02d",i+1); PutDbl(str,n2,1,scr); free(scr); nnsnodes[i]=n1; nnsdfac[i]=n2; } /* Store # nodes and # dis. factors per node set */ PutInt("nnsnodes",num_node_sets,1,nnsnodes); PutInt("nnsdfac",num_node_sets,1,nnsdfac); free(ids); free(nnsdfac); free(nnsnodes); } /* element blocks */ ids=(int *) calloc(num_blocks,sizeof(int)); num_elem_in_block=(int *) calloc(num_blocks,sizeof(int)); err = ex_get_ids(exo_file,EX_ELEM_BLOCK,ids); PutInt( "blkids",num_blocks, 1,ids); for (i=0;i<num_blocks;i++) { err = ex_get_elem_block(exo_file,ids[i],str2[i],&n,&n1,&n2); num_elem_in_block[i]=n; iscr = (int *) calloc(n*n1,sizeof(int)); err = ex_get_conn(exo_file,EX_ELEM_BLOCK,ids[i],iscr, NULL, NULL); sprintf(str,"blk%02d",i+1); PutInt(str,n1,n,iscr); free(iscr); } str[0]='\0'; for (i=0;i<num_blocks;i++) sprintf(str+strlen(str),"%s\n",str2[i]); PutStr("blknames",str); /* time values */ if (num_time_steps > 0 ) { scr = (double *) calloc (num_time_steps,sizeof(double)); err= ex_get_all_times (exo_file,scr); PutDbl( "time", num_time_steps, 1,scr); free(scr); } /* global variables */ if (num_global_vars > 0 ) { err = ex_get_variable_names(exo_file,EX_GLOBAL,num_global_vars,str2); str[0]='\0'; for (i=0;i<num_global_vars;i++) sprintf(str+strlen(str),"%s\n",str2[i]); PutStr("gnames",str); scr = (double *) calloc (num_time_steps,sizeof(double)); for (i=0;i<num_global_vars;i++){ sprintf(str,"gvar%02d",i+1); err=ex_get_glob_var_time(exo_file,i+1,1,num_time_steps,scr); PutDbl(str,num_time_steps,1,scr); } free(scr); } /* nodal variables */ if (num_nodal_vars > 0 ) { err = ex_get_variable_names(exo_file,EX_NODAL,num_nodal_vars,str2); str[0]='\0'; for (i=0;i<num_nodal_vars;i++) sprintf(str+strlen(str),"%s\n",str2[i]); PutStr("nnames",str); scr = (double *) calloc (num_nodes*num_time_steps,sizeof(double)); for (i=0;i<num_nodal_vars;i++){ sprintf(str,"nvar%02d",i+1); for (j=0;j<num_time_steps;j++) err=ex_get_nodal_var(exo_file,j+1,i+1,num_nodes, scr+num_nodes*j); PutDbl(str,num_nodes,num_time_steps,scr); } free(scr); } /* element variables */ if (num_element_vars > 0 ) { err = ex_get_variable_names(exo_file,EX_ELEM_BLOCK,num_element_vars,str2); str[0]='\0'; for (i=0;i<num_element_vars;i++) sprintf(str+strlen(str),"%s\n",str2[i]); PutStr("enames",str); /* truth table */ iscr = (int *) calloc(num_element_vars*num_blocks, sizeof(int)); ex_get_elem_var_tab(exo_file,num_blocks,num_element_vars,iscr); for (i=0;i<num_element_vars;i++){ scr = (double *) calloc (num_elements*num_time_steps,sizeof(double)); n=0; sprintf(str,"evar%02d",i+1); for (j=0;j<num_time_steps;j++){ for (k=0;k<num_blocks;k++){ if(iscr[num_element_vars*k+i]==1) ex_get_elem_var(exo_file,j+1,i+1,ids[k],num_elem_in_block[k],scr+n); n=n+num_elem_in_block[k]; } } PutDbl(str,num_elements,num_time_steps,scr); free(scr); } free(iscr); } free(num_elem_in_block); free(ids); /* node and element number maps */ ex_opts(0); /* turn off error reporting. It is not an error to have no map*/ ids = (int *)malloc(num_nodes*sizeof(int)); err = ex_get_node_num_map(exo_file,ids); if ( err==0 ){ PutInt("node_num_map",num_nodes,1,ids); } free(ids); ids = (int *)malloc(num_elements*sizeof(int)); err = ex_get_elem_num_map(exo_file,ids); if ( err==0 ){ PutInt("elem_num_map",num_elements,1,ids); } free(ids); /* close exo file */ ex_close(exo_file); /* close mat file */ if ( textfile ) fclose(m_file); else Mat_Close(mat_file); /* */ fprintf(stderr,"done.\n"); free(filename); free(line); free(str); for (i=0;i<nstr2;i++) free(str2[i]); free(str2); /* exit status */ add_to_log("exo2mat", 0); return(0); }
void write_to_exodus(int rank, int num_procs, char * out_file_name) /*****************************************************************************/ { int exo_access = EX_CLOBBER; int cpu_word_size = sizeof(double); int io_word_size = sizeof(float); int out_id; int i; int b; ex_init_params exinit; int error = 0; out_id = ex_create(out_file_name, exo_access, &cpu_word_size, &io_word_size); if (out_id < 0){ printf("error opening file"); } strncpy( exinit.title, mss.title, MAX_LINE_LENGTH-1 ); exinit.title[MAX_LINE_LENGTH-1] = 0; exinit.num_dim = mss.num_dim; exinit.num_nodes = mss.num_nodes; exinit.num_edge = 0; exinit.num_edge_blk = 0; exinit.num_face = 0; exinit.num_face_blk = 0; exinit.num_elem = mss.num_elem; exinit.num_elem_blk = mss.num_elem_blk; exinit.num_node_sets = mss.num_node_sets; exinit.num_edge_sets = 0; exinit.num_face_sets = 0; exinit.num_side_sets = mss.num_side_sets; exinit.num_elem_sets = 0; exinit.num_node_maps = 0; exinit.num_edge_maps = 0; exinit.num_face_maps = 0; exinit.num_elem_maps = 0; PERROR; if ( ex_put_init_ext(out_id, &exinit) < 0 ) ++error; PERROR; /*now write parallel global information*/ if ( ne_put_init_global( out_id, mss.num_nodes_global, mss.num_elems_global, mss.num_elm_blks_global, mss.num_node_sets_global, mss.num_side_sets_global ) < 0 ) ++error; PERROR; if ( ne_put_init_info( out_id, mss.num_total_proc, mss.num_proc_in_file, mss.type ) < 0 ) ++error; PERROR; if ( ne_put_eb_info_global(out_id,mss.elem_blk_ids_global,mss.elem_blk_cnts_global) < 0 ) ++error; PERROR; if ( mss.num_node_sets_global > 0 ) { if ( ne_put_ns_param_global( out_id, mss.ns_ids_global, mss.ns_cnts_global, mss.ns_df_cnts_global ) < 0 ) ++error; } PERROR; if ( mss.num_side_sets_global > 0 ) { if ( ne_put_ss_param_global( out_id, mss.ss_ids_global, mss.ss_cnts_global, mss.ss_df_cnts_global ) < 0 ) ++error; } PERROR; /*writingparallel info*/ if ( ne_put_loadbal_param( out_id, mss.num_internal_nodes, mss.num_border_nodes, mss.num_external_nodes, mss.num_internal_elems, mss.num_border_elems, mss.num_node_comm_maps, mss.num_elem_comm_maps, rank ) < 0 ) ++error; PERROR; if ( ne_put_cmap_params( out_id, mss.node_cmap_ids, (int*)mss.node_cmap_node_cnts, mss.elem_cmap_ids, (int*)mss.elem_cmap_elem_cnts, rank ) < 0 ) ++error; PERROR; if ( ne_put_elem_map( out_id, mss.internal_elements, mss.border_elements, rank ) < 0 ) ++error; PERROR; if ( ne_put_node_map( out_id, mss.internal_nodes, mss.border_nodes, mss.external_nodes, rank ) < 0 ) ++error; PERROR; for (i = 0; i < mss.num_node_comm_maps; i++) { if ( ne_put_node_cmap( out_id, mss.node_cmap_ids[i], mss.comm_node_ids[i], mss.comm_node_proc_ids[i], rank ) < 0 ) ++error; } PERROR; for (i = 0; i < mss.num_elem_comm_maps; i++) { if ( ne_put_elem_cmap( out_id, mss.elem_cmap_ids[i], mss.comm_elem_ids[i], mss.comm_side_ids[i], mss.comm_elem_proc_ids[i], rank ) < 0 ) ++error; } PERROR; /*coords*/ error += ex_put_coord(out_id, mss.coord, (mss.coord)+mss.num_nodes, (mss.coord)+2*mss.num_nodes); PERROR; error += ex_put_coord_names(out_id, mss.bptr); PERROR; /*map*/ error += ex_put_map(out_id, mss.element_order_map); PERROR; error += ex_put_elem_num_map(out_id, mss.global_element_numbers); PERROR; error += ex_put_node_num_map(out_id, mss.global_node_numbers); PERROR; /*block info*/ for(b = 0; b < mss.num_elem_blk; b++) { int gpe = 0; int fpe = 0; error += ex_put_block( out_id, EX_ELEM_BLOCK, mss.block_id[b], mss.element_types[b], mss.elements[b], mss.nodes_per_element[b], gpe, fpe, mss.element_attributes[b] ); /* num attr */ PERROR; } /* write element connectivity information */ for (b = 0; b < mss.num_elem_blk; b++) { if ( mss.elements[b] > 0 ){ error += ex_put_elem_conn(out_id,mss.block_id[b],mss.elmt_node_linkage[b]); PERROR; } } /* write in nodal boundary sets for the body. */ for(i = 0; i < mss.num_node_sets; i++) { error += ex_put_node_set_param(out_id, mss.node_set_id[i], mss.num_nodes_in_node_set[i], mss.num_df_in_node_set[i]); PERROR; if(mss.num_nodes_in_node_set[i]) error += ex_put_node_set(out_id, mss.node_set_id[i], mss.node_set_nodes[i]); PERROR; } for(i = 0; i < mss.num_side_sets; i++) { error += ex_put_side_set_param(out_id, mss.side_set_id[i], mss.num_elements_in_side_set[i], mss.num_df_in_side_set[i]); PERROR; if(mss.num_elements_in_side_set[i]) error += ex_put_side_set(out_id, mss.side_set_id[i], mss.side_set_elements[i], mss.side_set_faces[i]); PERROR; } error += ex_put_qa(out_id, mss.num_qa_records, mss.qaRecord); PERROR; ex_close(out_id); }
int cReadEdgeFace(int argc, char *argv[]) { int exoid; int appWordSize = 8; int diskWordSize = 8; float exoVersion; int itmp[5]; int * ids; int nids; int obj; int i, j; int num_timesteps; int ti; char ** obj_names; char ** var_names; int have_var_names; int num_vars; /* number of variables per object */ int num_entries; /* number of values per variable per object */ double * entry_vals; /* variable values for each entry of an object */ ex_init_params modelParams; exoid = ex_open(EX_TEST_FILENAME, EX_READ, &appWordSize, &diskWordSize, &exoVersion); if (exoid <= 0) { fprintf(stderr, "Unable to open \"%s\" for reading.\n", EX_TEST_FILENAME); return 1; } EXCHECK(ex_get_init_ext(exoid, &modelParams), "Unable to read database parameters.\n"); fprintf(stdout, "Title: <%s>\n" "Dimension: %" PRId64 "\n" "Nodes: %" PRId64 "\n" "Edges: %" PRId64 "\n" "Faces: %" PRId64 "\n" "Elements: %" PRId64 "\n" "Edge Blocks: %" PRId64 "\n" "Face Blocks: %" PRId64 "\n" "Element Blocks: %" PRId64 "\n" "Node Sets: %" PRId64 "\n" "Edge Sets: %" PRId64 "\n" "Face Sets: %" PRId64 "\n" "Side Sets: %" PRId64 "\n" "Element Sets: %" PRId64 "\n" "Node Maps: %" PRId64 "\n" "Edge Maps: %" PRId64 "\n" "Face Maps: %" PRId64 "\n" "Element Maps: %" PRId64 "\n", modelParams.title, modelParams.num_dim, modelParams.num_nodes, modelParams.num_edge, modelParams.num_face, modelParams.num_elem, modelParams.num_edge_blk, modelParams.num_face_blk, modelParams.num_elem_blk, modelParams.num_node_sets, modelParams.num_edge_sets, modelParams.num_face_sets, modelParams.num_side_sets, modelParams.num_elem_sets, modelParams.num_node_maps, modelParams.num_edge_maps, modelParams.num_face_maps, modelParams.num_elem_maps); num_timesteps = ex_inquire_int(exoid, EX_INQ_TIME); /* *** NEW API *** */ for (i = 0; i < sizeof(obj_types) / sizeof(obj_types[0]); ++i) { int *truth_tab = 0; have_var_names = 0; EXCHECK(ex_inquire(exoid, obj_sizes[i], &nids, 0, 0), "Object ID list size could not be determined.\n"); if (!nids) { fprintf(stdout, "=== %ss: none\n\n", obj_typenames[i]); continue; } else { fprintf(stdout, "=== %ss: %d\n", obj_typenames[i], nids); } ids = (int *)malloc(nids * sizeof(int)); obj_names = (char **)malloc(nids * sizeof(char *)); for (obj = 0; obj < nids; ++obj) obj_names[obj] = (char *)malloc((MAX_STR_LENGTH + 1) * sizeof(char)); EXCHECK(ex_get_ids(exoid, obj_types[i], ids), "Could not read object ids.\n"); EXCHECK(ex_get_names(exoid, obj_types[i], obj_names), "Could not read object ids.\n"); if ((OBJECT_IS_BLOCK(i)) || (OBJECT_IS_SET(i))) { int *tp; EXCHECK(ex_get_var_param(exoid, obj_typestr[i], &num_vars), "Could not read number of variables.\n"); if (num_vars && num_timesteps > 0) { truth_tab = (int *)malloc(num_vars * nids * sizeof(int)); EXCHECK(ex_get_var_tab(exoid, obj_typestr[i], nids, num_vars, truth_tab), "Could not read truth table.\n"); tp = truth_tab; fprintf(stdout, "Truth:"); for (obj = 0; obj < nids; ++obj) { for (j = 0; j < num_vars; ++j, ++tp) { fprintf(stdout, " %d", *tp); } fprintf(stdout, "\n "); } fprintf(stdout, "\n"); var_names = (char **)malloc(num_vars * sizeof(char *)); for (j = 0; j < num_vars; ++j) var_names[j] = (char *)malloc((MAX_STR_LENGTH + 1) * sizeof(char)); EXCHECK(ex_get_var_names(exoid, obj_typestr[i], num_vars, var_names), "Could not read variable names.\n"); have_var_names = 1; } } if (!have_var_names) var_names = 0; for (obj = 0; obj < nids; ++obj) { if (obj_names[obj]) fprintf(stdout, "%s %3d (%s): ", obj_typenames[i], ids[obj], obj_names[obj]); else fprintf(stdout, "%s %3d: ", obj_typenames[i], ids[obj]); if (OBJECT_IS_BLOCK(i)) { int *nconn; int *econn; int *fconn; int ele; int ctr; int num_attrs; if (obj_types[i] == EX_ELEM_BLOCK) { EXCHECK(ex_get_block(exoid, obj_types[i], ids[obj], 0, itmp, itmp + 1, itmp + 2, itmp + 3, &num_attrs), "Could not read block params.\n"); fprintf(stdout, "Entries: %3d Nodes/entry: %d Edges/entry: %d Faces/entry: %d Attributes: %d", itmp[0], itmp[1], itmp[2], itmp[3], num_attrs); } else { EXCHECK(ex_get_block(exoid, obj_types[i], ids[obj], 0, itmp, itmp + 1, 0, 0, &num_attrs), "Could not read block params.\n"); fprintf(stdout, "Entries: %3d Nodes/entry: %d Attributes: %d", itmp[0], itmp[1], num_attrs); itmp[2] = itmp[3] = 0; } fprintf(stdout, "\n "); num_entries = itmp[0]; nconn = itmp[1] ? (int *)malloc(itmp[1] * num_entries * sizeof(int)) : 0; econn = itmp[2] ? (int *)malloc(itmp[2] * num_entries * sizeof(int)) : 0; fconn = itmp[3] ? (int *)malloc(itmp[3] * num_entries * sizeof(int)) : 0; EXCHECK(ex_get_conn(exoid, obj_types[i], ids[obj], nconn, econn, fconn), "Could not read connectivity.\n"); for (ele = 0; ele < num_entries; ++ele) { for (ctr = 0; ctr < itmp[1]; ++ctr) { fprintf(stdout, " %2d", nconn[ele * itmp[1] + ctr]); } if (itmp[2]) { fprintf(stdout, " ++"); for (ctr = 0; ctr < itmp[2]; ++ctr) { fprintf(stdout, " %2d", econn[ele * itmp[2] + ctr]); } } if (itmp[3]) { fprintf(stdout, " ++"); for (ctr = 0; ctr < itmp[3]; ++ctr) { fprintf(stdout, " %2d", fconn[ele * itmp[3] + ctr]); } } fprintf(stdout, "\n "); } free(nconn); free(econn); free(fconn); if (num_attrs) { char ** attr_names; double *attr; attr = (double *)malloc(num_entries * num_attrs * sizeof(double)); attr_names = (char **)malloc(num_attrs * sizeof(char *)); for (j = 0; j < num_attrs; ++j) attr_names[j] = (char *)malloc((MAX_STR_LENGTH + 1) * sizeof(char)); EXCHECK(ex_get_attr_names(exoid, obj_types[i], ids[obj], attr_names), "Could not read attributes names.\n"); EXCHECK(ex_get_attr(exoid, obj_types[i], ids[obj], attr), "Could not read attribute values.\n"); fprintf(stdout, "\n Attributes:\n ID "); for (j = 0; j < num_attrs; ++j) fprintf(stdout, " %s", attr_names[j]); fprintf(stdout, "\n"); for (j = 0; j < num_entries; ++j) { int k; fprintf(stdout, " %2d ", j + 1); for (k = 0; k < num_attrs; ++k) { fprintf(stdout, " %4.1f", attr[j * num_attrs + k]); } fprintf(stdout, "\n"); } for (j = 0; j < num_attrs; ++j) free(attr_names[j]); free(attr_names); free(attr); } } else if (OBJECT_IS_SET(i)) { int num_df; int * set_entry; int * set_extra; double *set_df; EXCHECK(ex_get_set_param(exoid, obj_types[i], ids[obj], &num_entries, &num_df), "Could not read set parameters.\n"); set_entry = (int *)malloc(num_entries * sizeof(int)); set_extra = (obj_types[i] != EX_NODE_SET && obj_types[i] != EX_ELEM_SET) ? (int *)malloc(num_entries * sizeof(int)) : 0; EXCHECK(ex_get_set(exoid, obj_types[i], ids[obj], set_entry, set_extra), "Could not read set.\n"); fprintf(stdout, "Entries: %3d Distribution factors: %3d\n", num_entries, num_df); if (set_extra) { for (j = 0; j < num_entries; ++j) fprintf(stdout, " %2d %2d\n", set_entry[j], set_extra[j]); } else { for (j = 0; j < num_entries; ++j) fprintf(stdout, " %2d\n", set_entry[j]); } free(set_entry); free(set_extra); set_df = num_df ? (double *)malloc(num_df * sizeof(double)) : 0; if (set_df) { EXCHECK(ex_get_set_dist_fact(exoid, obj_types[i], ids[obj], set_df), "Could not read set distribution factors.\n"); fprintf(stdout, "\n Distribution factors:\n"); for (j = 0; j < num_df; ++j) fprintf(stdout, " %4.1f\n", set_df[j]); free(set_df); } } else { /* object is map */ int *map; switch (obj_types[i]) { case EX_NODE_MAP: num_entries = modelParams.num_nodes; break; case EX_EDGE_MAP: num_entries = modelParams.num_edge; break; case EX_FACE_MAP: num_entries = modelParams.num_face; break; case EX_ELEM_MAP: num_entries = modelParams.num_elem; break; default: num_entries = 0; } if (num_entries) { fprintf(stdout, "Entries: %3d\n :", num_entries); map = (int *)malloc(num_entries * sizeof(int)); EXCHECK(ex_get_num_map(exoid, obj_types[i], ids[obj], map), "Could not read map.\n"); for (j = 0; j < num_entries; ++j) { fprintf(stdout, " %d", map[j]); } } else { fprintf(stdout, "Entries: none"); } } fprintf(stdout, "\n"); /* Read results variables */ if (((OBJECT_IS_BLOCK(i)) || (OBJECT_IS_SET(i))) && num_vars && num_timesteps > 0) { /* Print out all the time values to exercise get_var */ entry_vals = (double *)malloc(num_entries * sizeof(double)); for (j = 0; j < num_vars; ++j) { int k; if (!truth_tab[num_vars * obj + j]) continue; fprintf(stdout, " Variable: %s", var_names[j]); for (ti = 1; ti <= num_timesteps; ++ti) { EXCHECK(ex_get_var(exoid, ti, obj_types[i], 1 + j, ids[obj], num_entries, entry_vals), "Could not read variable values.\n"); fprintf(stdout, "\n @t%d ", ti); for (k = 0; k < num_entries; ++k) { fprintf(stdout, " %4.1f", entry_vals[k]); } } fprintf(stdout, "\n"); } fprintf(stdout, "\n"); free(entry_vals); } } if (((OBJECT_IS_BLOCK(i)) || (OBJECT_IS_SET(i))) && num_vars && num_timesteps > 0) { /* Print out one element's time values to exercise get_var_time */ entry_vals = (double *)malloc(num_timesteps * sizeof(double)); EXCHECK(ex_inquire(exoid, obj_sizeinq[i], itmp, 0, 0), "Inquire failed.\n"); itmp[1] = 11; while (itmp[1] > itmp[0]) itmp[1] /= 2; for (j = 0; j < num_vars; ++j) { /* FIXME: This works for the dataset created by CreateEdgeFace, but not for any dataset in * general since * NULL truth table entries may mean the referenced elements don't have variable values. */ EXCHECK(ex_get_var_time(exoid, obj_types[i], j + 1, itmp[1], 1, num_timesteps, entry_vals), "Could not read variable over time.\n"); fprintf(stdout, " Variable over time: %s Entry: %3d ", var_names[j], itmp[1]); for (ti = 1; ti <= num_timesteps; ++ti) fprintf(stdout, " @t%d: %4.1f", ti, entry_vals[ti - 1]); fprintf(stdout, "\n"); } free(entry_vals); } if (var_names) { for (j = 0; j < num_vars; ++j) free(var_names[j]); free(var_names); } free(truth_tab); free(ids); for (obj = 0; obj < nids; ++obj) free(obj_names[obj]); free(obj_names); fprintf(stdout, "\n"); } EXCHECK(ex_close(exoid), "Unable to close database.\n"); return 0; }