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; }
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 cCreateEdgeFace( int argc, char* argv[] ) { int exoid; int appWordSize = 8; int diskWordSize = 8; /* int concatBlocks = ex_have_arg( argc, argv, "-pcab" ); */ int concatSets = ex_have_arg( argc, argv, "-pcset" ); int concatResult = ex_have_arg( argc, argv, "-pvpax" ); double t; ex_init_params modelParams = { "CreateEdgeFace Test", /* title */ 3, /* num_dim */ 12, /* num_nodes */ 20, /* num_edge */ 1, /* num_edge_blk */ 11, /* num_face */ 3, /* num_face_blk */ 3, /* num_elem */ 2, /* num_elem_blk */ 1, /* num_node_sets */ 1, /* num_edge_sets */ 1, /* num_face_sets */ 1, /* num_side_sets */ 2, /* num_elem_sets */ 1, /* num_node_map */ 1, /* num_edge_map */ 1, /* num_face_map */ 1, /* num_elem_map */ }; ex_block edgeBlocks[1]; ex_block faceBlocks[3]; ex_block elemBlocks[2]; ex_var_params varParams; ex_opts (EX_VERBOSE | EX_ABORT ); edgeBlocks[0].type = EX_EDGE_BLOCK; edgeBlocks[0].id = 100; edgeBlocks[0].num_entry = 20; edgeBlocks[0].num_nodes_per_entry = 2; edgeBlocks[0].num_attribute = 1; strcpy(edgeBlocks[0].topology, "EDGE2"); faceBlocks[0].type = EX_FACE_BLOCK; faceBlocks[0].id = 500; faceBlocks[0].num_entry = 2; faceBlocks[0].num_nodes_per_entry = 4; faceBlocks[0].num_attribute = 1; strcpy(faceBlocks[0].topology, "QUAD4"); faceBlocks[1].type = EX_FACE_BLOCK; faceBlocks[1].id = 600; faceBlocks[1].num_entry = 1; faceBlocks[1].num_nodes_per_entry = 4; faceBlocks[1].num_attribute = 1; strcpy(faceBlocks[1].topology, "QUAD4"); faceBlocks[2].type = EX_FACE_BLOCK; faceBlocks[2].id = 700; faceBlocks[2].num_entry = 8; faceBlocks[2].num_nodes_per_entry = 4; faceBlocks[2].num_attribute = 1; strcpy(faceBlocks[2].topology, "QUAD4"); elemBlocks[0].type = EX_ELEM_BLOCK; elemBlocks[0].id = 200; elemBlocks[0].num_entry = 2; elemBlocks[0].num_nodes_per_entry = 8; elemBlocks[0].num_edges_per_entry = 12; elemBlocks[0].num_faces_per_entry = 6; elemBlocks[0].num_attribute = 2; strcpy(elemBlocks[0].topology, "HEX8"); elemBlocks[1].type = EX_ELEM_BLOCK; elemBlocks[1].id = 201; elemBlocks[1].num_entry = 1; elemBlocks[1].num_nodes_per_entry = 4; elemBlocks[1].num_edges_per_entry = 0; elemBlocks[1].num_faces_per_entry = 0; elemBlocks[1].num_attribute = 0; strcpy(elemBlocks[1].topology, "TET4"); varParams.edge_var_tab = (int*)malloc(2 * sizeof(int)); varParams.face_var_tab = (int*)malloc(3 * sizeof(int)); varParams.elem_var_tab = (int*)malloc(2 * sizeof(int)); varParams.nset_var_tab = (int*)0; varParams.eset_var_tab = (int*)0; varParams.fset_var_tab = (int*)malloc(1 * sizeof(int)); varParams.sset_var_tab = (int*)0; varParams.elset_var_tab = (int*)0; varParams.num_glob = 2; varParams.num_node = 1; varParams.num_edge = 2; varParams.edge_var_tab[0] = 1; varParams.edge_var_tab[1] = 1; varParams.num_face = 1; varParams.face_var_tab[0] = 1; varParams.face_var_tab[1] = 1; varParams.face_var_tab[2] = 1; varParams.num_elem = 1; varParams.elem_var_tab[0] = 1; varParams.elem_var_tab[1] = 0; varParams.num_nset = 0; varParams.num_eset = 0;; varParams.num_fset = 1; varParams.fset_var_tab[0] = 1; varParams.num_sset = 0; varParams.num_elset = 0; exoid = ex_create( EX_TEST_FILENAME, EX_CLOBBER, &appWordSize, &diskWordSize ); if ( exoid <= 0 ) { fprintf( stderr, "Unable to open \"%s\" for writing.\n", EX_TEST_FILENAME ); return 1; } EXCHECK( ex_put_init_ext( exoid, &modelParams ), "Unable to initialize database.\n" ); { int blk; for ( blk = 0; blk < modelParams.num_edge_blk; ++blk ) { EXCHECK( ex_put_block_param( exoid, edgeBlocks[blk]), "Unable to write edge block" ); } for ( blk = 0; blk < modelParams.num_face_blk; ++blk ) { EXCHECK( ex_put_block_param( exoid, faceBlocks[blk]), "Unable to write face block" ); } for ( blk = 0; blk < modelParams.num_elem_blk; ++blk ) { EXCHECK( ex_put_block_param( exoid, elemBlocks[blk]), "Unable to write elem block" ); } } EXCHECK( ex_put_coord( exoid, (void*)coordsX, (void*)coordsY, (void*)coordsZ ), "Unable to write coordinates.\n" ); EXCHECK( ex_put_coord_names( exoid, (char**)coordsNames ), "Unable to write coordinate names.\n" ); /* =============== Connectivity ================== */ /* *** NEW API *** */ EXCHECK( ex_put_conn( exoid, EX_EDGE_BLOCK, edgeBlocks[0].id, ebconn1, 0, 0 ), "Unable to write edge block connectivity.\n" ); /* *** NEW API *** */ EXCHECK( ex_put_conn( exoid, EX_FACE_BLOCK, faceBlocks[0].id, fbconn1, 0, 0 ), "Unable to write face block 1 connectivity.\n" ); EXCHECK( ex_put_conn( exoid, EX_FACE_BLOCK, faceBlocks[1].id, fbconn2, 0, 0 ), "Unable to write face block 2 connectivity.\n" ); EXCHECK( ex_put_conn( exoid, EX_FACE_BLOCK, faceBlocks[2].id, fbconn3, 0, 0 ), "Unable to write face block 3 connectivity.\n" ); /* *** NEW API *** */ EXCHECK( ex_put_conn( exoid, EX_ELEM_BLOCK, elemBlocks[0].id, conn1, econn1, fconn1 ), "Unable to write elem block 1 connectivity.\n" ); /* *** NEW API *** */ EXCHECK( ex_put_conn( exoid, EX_ELEM_BLOCK, elemBlocks[1].id, conn2, 0, 0 ), "Unable to write elem block 2 connectivity.\n" ); /* *** NEW API *** */ EXCHECK( ex_put_names( exoid, EX_EDGE_BLOCK, (char**)edblk_names ), "Unable to write edge block names.\n" ); EXCHECK( ex_put_names( exoid, EX_FACE_BLOCK, (char**)fablk_names ), "Unable to write face block names.\n" ); EXCHECK( ex_put_names( exoid, EX_ELEM_BLOCK, (char**) eblk_names ), "Unable to write element block names.\n" ); /* =============== Number Maps ================== */ /* *** NEW API *** */ EXCHECK( ex_put_num_map( exoid, EX_NODE_MAP, 300, nmap1 ), "Unable to write node map.\n" ); EXCHECK( ex_put_num_map( exoid, EX_EDGE_MAP, 800, edmap1 ), "Unable to write edge map.\n" ); EXCHECK( ex_put_num_map( exoid, EX_FACE_MAP, 900, famap1 ), "Unable to write face map.\n" ); EXCHECK( ex_put_num_map( exoid, EX_ELEM_MAP, 400, emap1 ), "Unable to write element map.\n" ); /* *** NEW API *** */ EXCHECK( ex_put_names( exoid, EX_NODE_MAP, (char**) nmap_names ), "Unable to write node map names.\n" ); EXCHECK( ex_put_names( exoid, EX_EDGE_MAP, (char**)edmap_names ), "Unable to write edge map names.\n" ); EXCHECK( ex_put_names( exoid, EX_FACE_MAP, (char**)famap_names ), "Unable to write face map names.\n" ); EXCHECK( ex_put_names( exoid, EX_ELEM_MAP, (char**) emap_names ), "Unable to write element map names.\n" ); /* =============== Attribute names ================ */ /* *** NEW API *** */ EXCHECK( ex_put_attr_names( exoid, EX_EDGE_BLOCK, edgeBlocks[0].id, (char**)edge_attr_names1 ), "Unable to write edge block 1 attribute names.\n" ); /* *** NEW API *** */ EXCHECK( ex_put_attr_names( exoid, EX_FACE_BLOCK, faceBlocks[0].id, (char**)face_attr_names1 ), "Unable to write face block 1 attribute names.\n" ); EXCHECK( ex_put_attr_names( exoid, EX_FACE_BLOCK, faceBlocks[1].id, (char**)face_attr_names2 ), "Unable to write face block 1 attribute names.\n" ); EXCHECK( ex_put_attr_names( exoid, EX_FACE_BLOCK, faceBlocks[2].id, (char**)face_attr_names3 ), "Unable to write face block 1 attribute names.\n" ); /* *** NEW API *** */ EXCHECK( ex_put_attr_names( exoid, EX_ELEM_BLOCK, elemBlocks[0].id, (char**)elem_attr_names1 ), "Unable to write elem block 1 attribute names.\n" ); /* =============== Attribute values =============== */ /* *** NEW API *** */ EXCHECK( ex_put_attr( exoid, EX_EDGE_BLOCK, edgeBlocks[0].id, edge_attr_values1 ), "Unable to write edge block 1 attribute values.\n" ); /* *** NEW API *** */ EXCHECK( ex_put_attr( exoid, EX_FACE_BLOCK, faceBlocks[0].id, face_attr_values1 ), "Unable to write face block 1 attribute values.\n" ); EXCHECK( ex_put_attr( exoid, EX_FACE_BLOCK, faceBlocks[1].id, face_attr_values2 ), "Unable to write face block 1 attribute values.\n" ); EXCHECK( ex_put_attr( exoid, EX_FACE_BLOCK, faceBlocks[2].id, face_attr_values3 ), "Unable to write face block 1 attribute values.\n" ); /* *** NEW API *** */ EXCHECK( ex_put_attr( exoid, EX_ELEM_BLOCK, elemBlocks[0].id, elem_attr_values1 ), "Unable to write elem block 1 attribute values.\n" ); /* =============== Set parameters ================= */ /* *** NEW API *** */ EXCHECK( ex_put_names( exoid, EX_NODE_SET, (char**)nset_names ), "Unable to write node set names.\n" ); EXCHECK( ex_put_names( exoid, EX_EDGE_SET, (char**)eset_names ), "Unable to write edge set names.\n" ); EXCHECK( ex_put_names( exoid, EX_FACE_SET, (char**)fset_names ), "Unable to write face set names.\n" ); EXCHECK( ex_put_names( exoid, EX_SIDE_SET, (char**)sset_names ), "Unable to write side set names.\n" ); EXCHECK( ex_put_names( exoid, EX_ELEM_SET, (char**)elset_names ), "Unable to write element set names.\n" ); { ex_set allSets[1+1+1+1+2]; ex_set *nodeSets = &allSets[0]; ex_set *edgeSets = &allSets[1]; ex_set *faceSets = &allSets[2]; ex_set *sideSets = &allSets[3]; ex_set *elemSets = &allSets[4]; nodeSets[0].type = EX_NODE_SET; nodeSets[0].id = 1000; nodeSets[0].num_entry = 3; nodeSets[0].num_distribution_factor = 0; nodeSets[0].entry_list = nset_nodes; nodeSets[0].extra_list = NULL; nodeSets[0].distribution_factor_list = NULL; edgeSets[0].type = EX_EDGE_SET; edgeSets[0].id = 1200; edgeSets[0].num_entry = 6; edgeSets[0].num_distribution_factor = 6; edgeSets[0].entry_list = eset_edges; edgeSets[0].extra_list = eset_orient; edgeSets[0].distribution_factor_list = eset_df; faceSets[0].type = EX_FACE_SET; faceSets[0].id = 1400; faceSets[0].num_entry = 2; faceSets[0].num_distribution_factor = 0; faceSets[0].entry_list = fset_faces; faceSets[0].extra_list = fset_orient; faceSets[0].distribution_factor_list = NULL; sideSets[0].type = EX_SIDE_SET; sideSets[0].id = 1400; sideSets[0].num_entry = 5; sideSets[0].num_distribution_factor = 0; sideSets[0].entry_list = sset_elems; sideSets[0].extra_list = sset_sides; sideSets[0].distribution_factor_list = NULL; elemSets[0].type = EX_ELEM_SET; elemSets[0].id = 1800; elemSets[0].num_entry = 1; elemSets[0].num_distribution_factor = 0; elemSets[0].entry_list = &elset_elems[0]; elemSets[0].extra_list = NULL; elemSets[0].distribution_factor_list = NULL; elemSets[1].type = EX_ELEM_SET; elemSets[1].id = 1900; elemSets[1].num_entry = 1; elemSets[1].num_distribution_factor = 0; elemSets[1].entry_list = &elset_elems[1]; elemSets[1].extra_list = NULL; elemSets[1].distribution_factor_list = NULL; if ( concatSets ) { EXCHECK( ex_put_sets(exoid, 1+2+1+1+1, allSets), "Unable to output concatenated sets.\n" ); } else { EXCHECK( ex_put_sets( exoid, 1, nodeSets), "Unable to write node sets.\n" ); EXCHECK( ex_put_sets( exoid, 1, edgeSets), "Unable to write edge sets.\n" ); EXCHECK( ex_put_sets( exoid, 1, faceSets), "Unable to write face sets.\n" ); EXCHECK( ex_put_sets( exoid, 1, sideSets), "Unable to write side sets.\n" ); EXCHECK( ex_put_sets( exoid, 2, elemSets), "Unable to write element sets.\n" ); } } /* =============== Result variable params ========= */ /* *** NEW API *** */ if ( concatResult ) { EXCHECK( ex_put_all_var_param_ext( exoid, &varParams ), "Unable to write result variable parameter information.\n" ); } else { EXCHECK( ex_put_var_param( exoid, "G", 2 ), "Unable to write global result variable parameters.\n" ); EXCHECK( ex_put_var_param( exoid, "N", 1 ), "Unable to write nodal result variable parameters.\n" ); EXCHECK( ex_put_var_param( exoid, "E", 1 ), "Unable to write element result variable parameters.\n" ); EXCHECK( ex_put_var_param( exoid, "L", 2 ), "Unable to write edge result variable parameters.\n" ); EXCHECK( ex_put_var_param( exoid, "F", 1 ), "Unable to write face result variable parameters.\n" ); EXCHECK( ex_put_var_param( exoid, "A", 1 ), "Unable to write faceset result variable parameters.\n" ); } /* =============== Result variable names ========== */ /* *** NEW API *** */ EXCHECK( ex_put_var_name( exoid, "G", 1, "CALIBER" ), "Unable to write variable name.\n" ); EXCHECK( ex_put_var_name( exoid, "g", 2, "GUNPOWDER" ), "Unable to write variable name.\n" ); EXCHECK( ex_put_var_name( exoid, "N", 1, "RHO" ), "Unable to write variable name.\n" ); EXCHECK( ex_put_var_name( exoid, "l", 1, "GAMMA1" ), "Unable to write variable name.\n" ); EXCHECK( ex_put_var_name( exoid, "L", 2, "GAMMA2" ), "Unable to write variable name.\n" ); EXCHECK( ex_put_var_name( exoid, "f", 1, "PHI" ), "Unable to write variable name.\n" ); EXCHECK( ex_put_var_name( exoid, "E", 1, "EPSTRN" ), "Unable to write variable name.\n" ); EXCHECK( ex_put_var_name( exoid, "A", 1, "PHI0" ), "Unable to write variable name.\n" ); /* =============== Result variable values ========= */ t = 1.; /* *** NEW API *** */ EXCHECK( ex_put_time( exoid, 1, &t ), "Unable to write time value.\n" ); EXCHECK( ex_put_var( exoid, 1, EX_GLOBAL, 1, 0/*N/A*/, 2, vals_glo_var[0] ), "Unable to write global var 1.\n" ); EXCHECK( ex_put_var( exoid, 1, EX_EDGE_BLOCK, 1, 100, 20, vals_edge_var1eb1[0] ), "Unable to write edge block 1 var 1.\n" ); EXCHECK( ex_put_var( exoid, 1, EX_EDGE_BLOCK, 2, 100, 20, vals_edge_var2eb1[0] ), "Unable to write edge block 1 var 2.\n" ); EXCHECK( ex_put_var( exoid, 1, EX_FACE_BLOCK, 1, 500, 2, vals_face_var1fb1[0] ), "Unable to write face block 1 var 1.\n" ); EXCHECK( ex_put_var( exoid, 1, EX_FACE_BLOCK, 1, 700, 8, vals_face_var1fb3[0] ), "Unable to write face block 3 var 1.\n" ); EXCHECK( ex_put_var( exoid, 1, EX_ELEM_BLOCK, 1, 200, 2, vals_elem_var1eb1[0] ), "Unable to write elem block 1 var 1.\n" ); EXCHECK( ex_put_var( exoid, 1, EX_FACE_SET, 1, 1400, 2, vals_fset_var1fs1[0] ), "Unable to write face set 1 var 1.\n" ); t = 2.; EXCHECK( ex_put_time( exoid, 2, &t ), "Unable to write time value.\n" ); EXCHECK( ex_put_var( exoid, 2, EX_GLOBAL, 1, 0/*N/A*/, 2, vals_glo_var[1] ), "Unable to write global var 1.\n" ); EXCHECK( ex_put_var( exoid, 2, EX_EDGE_BLOCK, 1, 100, 20, vals_edge_var1eb1[1] ), "Unable to write edge block 1 var 1.\n" ); EXCHECK( ex_put_var( exoid, 2, EX_EDGE_BLOCK, 2, 100, 20, vals_edge_var2eb1[1] ), "Unable to write edge block 1 var 2.\n" ); EXCHECK( ex_put_var( exoid, 2, EX_FACE_BLOCK, 1, 500, 2, vals_face_var1fb1[1] ), "Unable to write face block 1 var 1.\n" ); EXCHECK( ex_put_var( exoid, 2, EX_FACE_BLOCK, 1, 700, 8, vals_face_var1fb3[1] ), "Unable to write face block 3 var 1.\n" ); EXCHECK( ex_put_var( exoid, 2, EX_ELEM_BLOCK, 1, 200, 2, vals_elem_var1eb1[1] ), "Unable to write elem block 1 var 1.\n" ); EXCHECK( ex_put_var( exoid, 2, EX_FACE_SET, 1, 1400, 2, vals_fset_var1fs1[1] ), "Unable to write face set 1 var 1.\n" ); EXCHECK( ex_put_nodal_var( exoid, 1, 1, 12, vals_nod_var[0] ), "Unable to write nodal var 1.\n" ); EXCHECK( ex_put_nodal_var( exoid, 2, 1, 12, vals_nod_var[1] ), "Unable to write nodal var 1.\n" ); EXCHECK( ex_close( exoid ), "Unable to close database.\n" ); return 0; }