Exodus 7.22

/test/testwt.c
/*
* Copyright (c) 2005-2017 National Technology & Engineering Solutions
* of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
* NTESS, the U.S. Government retains certain rights in this software.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* * Neither the name of NTESS nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/*****************************************************************************
*
* testwt - test write an ExodusII database file
*
* author - Sandia National Laboratories
* Larry A. Schoof - Original
* Vic Yarberry - Added headers and error logging
* 7/7/93 Modified for use with Exodus 2.00
*
*
* environment - UNIX
*
* entry conditions -
*
* exit conditions -
*
* revision history -
*
* This is a test program for the C binding of the EXODUS II
* database write routines.
*
*
*****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "exodusII.h"
#include "exodusII_int.h"
int main(int argc, char **argv)
{
int exoid, num_dim, num_nodes, num_elem, num_elem_blk;
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 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], *var_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";
struct ex_block blocks[10];
ex_opts(EX_VERBOSE);
/* 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 = 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);
}
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);
}
/* 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 */
for (i = 0; i < 10; i++) {
blocks[i].type = EX_ELEM_BLOCK;
blocks[i].id = 0;
blocks[i].num_entry = 0;
blocks[i].num_nodes_per_entry = 0;
blocks[i].num_edges_per_entry = 0;
blocks[i].num_faces_per_entry = 0;
blocks[i].num_attribute = 0;
}
block_names[0] = "block_1";
block_names[1] = "block_2";
block_names[2] = "block_3";
block_names[3] = "block_4";
block_names[4] = "block_5";
block_names[5] = "block_6";
block_names[6] = "block_7";
ex_copy_string(blocks[0].topology, "quad", MAX_STR_LENGTH + 1);
ex_copy_string(blocks[1].topology, "quad", MAX_STR_LENGTH + 1);
ex_copy_string(blocks[2].topology, "hex", MAX_STR_LENGTH + 1);
ex_copy_string(blocks[3].topology, "tetra", MAX_STR_LENGTH + 1);
ex_copy_string(blocks[4].topology, "wedge", MAX_STR_LENGTH + 1);
ex_copy_string(blocks[5].topology, "tetra", MAX_STR_LENGTH + 1);
ex_copy_string(blocks[6].topology, "tri", MAX_STR_LENGTH + 1);
blocks[0].num_entry = 1;
blocks[1].num_entry = 1;
blocks[2].num_entry = 1;
blocks[3].num_entry = 1;
blocks[4].num_entry = 1;
blocks[5].num_entry = 1;
blocks[6].num_entry = 1;
blocks[0].num_attribute = 1;
blocks[1].num_attribute = 1;
blocks[2].num_attribute = 1;
blocks[3].num_attribute = 1;
blocks[4].num_attribute = 1;
blocks[5].num_attribute = 1;
blocks[6].num_attribute = 1;
blocks[0].num_nodes_per_entry = 4; /* elements in block #1 are 4-node quads */
blocks[1].num_nodes_per_entry = 4; /* elements in block #2 are 4-node quads */
blocks[2].num_nodes_per_entry = 8; /* elements in block #3 are 8-node hexes */
blocks[3].num_nodes_per_entry = 4; /* elements in block #4 are 4-node tetras */
blocks[4].num_nodes_per_entry = 6; /* elements in block #5 are 6-node wedges */
blocks[5].num_nodes_per_entry = 8; /* elements in block #6 are 8-node tetras */
blocks[6].num_nodes_per_entry = 3; /* elements in block #7 are 3-node tris */
blocks[0].id = 10;
blocks[1].id = 11;
blocks[2].id = 12;
blocks[3].id = 13;
blocks[4].id = 14;
blocks[5].id = 15;
blocks[6].id = 16;
/* Generate an error that name is not found since blocks have not
yet been defined
*/
error = ex_put_name(exoid, EX_ELEM_BLOCK, blocks[0].id, block_names[0]);
printf("after ex_put_name, error = %d\n", error);
error = ex_put_block_params(exoid, num_elem_blk, blocks);
printf("after ex_put_block_params, error = %d\n", error);
if (error) {
ex_close(exoid);
exit(-1);
}
/* Write element block names */
for (i = 0; i < num_elem_blk; i++) {
error = ex_put_name(exoid, EX_ELEM_BLOCK, blocks[i].id, block_names[i]);
printf("after ex_put_names, error = %d\n", error);
}
if (error) {
ex_close(exoid);
exit(-1);
}
/* write element block properties */
/* 12345678901234567890123456789012 */
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, blocks[0].id, 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, blocks[1].id, 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, blocks[2].id, 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, blocks[3].id, 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, blocks[4].id, 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, blocks[5].id, 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, blocks[6].id, 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_conn(exoid, EX_ELEM_BLOCK, blocks[0].id, connect, NULL, NULL);
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_conn(exoid, EX_ELEM_BLOCK, blocks[1].id, connect, NULL, NULL);
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_conn(exoid, EX_ELEM_BLOCK, blocks[2].id, connect, NULL, NULL);
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_conn(exoid, EX_ELEM_BLOCK, blocks[3].id, connect, NULL, NULL);
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_conn(exoid, EX_ELEM_BLOCK, blocks[4].id, connect, NULL, NULL);
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_conn(exoid, EX_ELEM_BLOCK, blocks[5].id, connect, NULL, NULL);
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_conn(exoid, EX_ELEM_BLOCK, blocks[6].id, connect, NULL, NULL);
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_attr(exoid, EX_ELEM_BLOCK, blocks[0].id, attrib);
printf("after ex_put_elem_attr, error = %d\n", error);
if (error) {
ex_close(exoid);
exit(-1);
}
error = ex_put_attr(exoid, EX_ELEM_BLOCK, blocks[0].id, 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_attr(exoid, EX_ELEM_BLOCK, blocks[1].id, attrib);
printf("after ex_put_elem_attr, error = %d\n", error);
if (error) {
ex_close(exoid);
exit(-1);
}
error = ex_put_attr(exoid, EX_ELEM_BLOCK, blocks[2].id, attrib);
printf("after ex_put_elem_attr, error = %d\n", error);
if (error) {
ex_close(exoid);
exit(-1);
}
error = ex_put_attr(exoid, EX_ELEM_BLOCK, blocks[3].id, attrib);
printf("after ex_put_elem_attr, error = %d\n", error);
if (error) {
ex_close(exoid);
exit(-1);
}
error = ex_put_attr(exoid, EX_ELEM_BLOCK, blocks[4].id, attrib);
printf("after ex_put_elem_attr, error = %d\n", error);
if (error) {
ex_close(exoid);
exit(-1);
}
error = ex_put_attr(exoid, EX_ELEM_BLOCK, blocks[5].id, attrib);
printf("after ex_put_elem_attr, error = %d\n", error);
if (error) {
ex_close(exoid);
exit(-1);
}
error = ex_put_attr(exoid, EX_ELEM_BLOCK, blocks[6].id, attrib);
printf("after ex_put_elem_attr, error = %d\n", error);
if (error) {
ex_close(exoid);
exit(-1);
}
attrib_names[0] = "THICKNESS";
for (i = 0; i < num_elem_blk; i++) {
error = ex_put_attr_names(exoid, EX_ELEM_BLOCK, blocks[i].id, 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_set_param(exoid, EX_NODE_SET, 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_set(exoid, EX_NODE_SET, nsids[0], node_list, NULL);
printf("after ex_put_node_set, error = %d\n", error);
if (error) {
ex_close(exoid);
exit(-1);
}
error = ex_put_set_dist_fact(exoid, EX_NODE_SET, 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_set_param(exoid, EX_NODE_SET, 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_set(exoid, EX_NODE_SET, nsids[1], node_list, NULL);
printf("after ex_put_node_set, error = %d\n", error);
if (error) {
ex_close(exoid);
exit(-1);
}
error = ex_put_set_dist_fact(exoid, EX_NODE_SET, 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_set_param(exoid, EX_SIDE_SET, 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_set(exoid, EX_SIDE_SET, 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_set_dist_fact(exoid, EX_SIDE_SET, 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_set_param(exoid, EX_SIDE_SET, 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_set(exoid, EX_SIDE_SET, 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_set_dist_fact(exoid, EX_SIDE_SET, 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_set_param(exoid, EX_SIDE_SET, 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_set(exoid, EX_SIDE_SET, 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_set_param(exoid, EX_SIDE_SET, 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_set(exoid, EX_SIDE_SET, 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_set_param(exoid, EX_SIDE_SET, 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_set(exoid, EX_SIDE_SET, 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] = "Thirty-Two character QA Record|";
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] = "This info record is exactly 80 characters long. last character should be pipe |";
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_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, var_names);
printf("after ex_put_variable_names, error = %d\n", error);
if (error) {
ex_close(exoid);
exit(-1);
}
num_nod_vars = 2;
/* 12345678901234567890123456789012 */
var_names[0] = "node_variable_a_very_long_name_0";
var_names[1] = "nod_var1";
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, var_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 */
/* 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";
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, var_names);
printf("after ex_put_variable_names, error = %d\n", error);
if (error) {
ex_close(exoid);
exit(-1);
}
{
num_nset_vars = 3;
var_names[0] = "ns_var0";
var_names[1] = "ns_var1";
var_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, var_names);
printf("after ex_put_variable_names, error = %d\n", error);
if (error) {
ex_close(exoid);
exit(-1);
}
}
{
num_sset_vars = 3;
var_names[0] = "ss_var0";
var_names[1] = "ss_var1";
var_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, var_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_truth_table(exoid, EX_ELEM_BLOCK, 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_var(exoid, whole_time_step, EX_GLOBAL, 1, 1, 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_var(exoid, whole_time_step, EX_NODAL, k, 1, 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 < blocks[j].num_entry; 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_var(exoid, whole_time_step, EX_ELEM_BLOCK, k, blocks[j].id,
blocks[j].num_entry, 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_var(exoid, whole_time_step, EX_SIDE_SET, 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_var(exoid, whole_time_step, EX_NODE_SET, 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;
}
EX_NODE_SET
Definition: exodusII.h:256
ex_block::num_entry
int64_t num_entry
Definition: exodusII.h:355
ex_put_names
int ex_put_names(int exoid, ex_entity_type obj_type, char *names[])
Definition: ex_put_names.c:63
truth_tab
truth_tab
Definition: ex_put_elem_var_tab.c:108
ex_put_truth_table
int ex_put_truth_table(int exoid, ex_entity_type obj_type, int num_blk, int num_var, int *var_tab)
Definition: ex_put_truth_table.c:93
ex_put_qa
int ex_put_qa(int exoid, int num_qa_records, char *qa_record[][4])
Definition: ex_put_qa.c:90
ex_opts
int ex_opts(int options)
Definition: ex_opts.c:83
ex_put_name
int ex_put_name(int exoid, ex_entity_type obj_type, ex_entity_id entity_id, const char *name)
Definition: ex_put_name.c:67
error
error
Definition: ex_put_elem_var_tab.c:115
ex_put_prop_array
int ex_put_prop_array(int exoid, ex_entity_type obj_type, const char *prop_name, const void_int *values)
Definition: ex_put_prop_array.c:98
ex_put_set_dist_fact
int ex_put_set_dist_fact(int exoid, ex_entity_type set_type, ex_entity_id set_id, const void *set_dist_fact)
Definition: ex_put_set_dist_fact.c:63
ex_put_prop_names
int ex_put_prop_names(int exoid, ex_entity_type obj_type, int num_props, char **prop_names)
Definition: ex_put_prop_names.c:124
ex_block::num_attribute
int64_t num_attribute
Definition: exodusII.h:359
ex_block::id
int64_t id
Definition: exodusII.h:352
ex_put_variable_param
int ex_put_variable_param(int exoid, ex_entity_type obj_type, int num_vars)
Definition: ex_put_variable_param.c:152
ex_put_time
int ex_put_time(int exoid, int time_step, const void *time_value)
Definition: ex_put_time.c:78
ex_put_attr_names
int ex_put_attr_names(int exoid, ex_entity_type blk_type, ex_entity_id blk_id, char **names)
ex_put_set_param
int ex_put_set_param(int exoid, ex_entity_type set_type, ex_entity_id set_id, int64_t num_entries_in_set, int64_t num_dist_fact_in_set)
Definition: ex_put_set_param.c:65
ex_put_prop
int ex_put_prop(int exoid, ex_entity_type obj_type, ex_entity_id obj_id, const char *prop_name, ex_entity_id value)
Definition: ex_put_prop.c:103
EX_SIDE_SET
Definition: exodusII.h:264
ex_create
#define ex_create(path, mode, comp_ws, io_ws)
Definition: exodusII.h:444
ex_block::num_nodes_per_entry
int64_t num_nodes_per_entry
Definition: exodusII.h:356
MAX_STR_LENGTH
#define MAX_STR_LENGTH
Definition: exodusII.h:300
ex_close
int ex_close(int exoid)
Definition: ex_close.c:73
ex_put_coord_names
int ex_put_coord_names(int exoid, char *coord_names[])
Definition: ex_put_coord_names.c:73
ex_put_set
int ex_put_set(int exoid, ex_entity_type set_type, ex_entity_id set_id, const void_int *set_entry_list, const void_int *set_extra_list)
Definition: ex_put_set.c:67
ex_block
Definition: exodusII.h:350
EX_GLOBAL
Definition: exodusII.h:271
ex_put_variable_names
int ex_put_variable_names(int exoid, ex_entity_type obj_type, int num_vars, char *var_names[])
Definition: ex_put_variable_names.c:151
ex_put_attr_param
int ex_put_attr_param(int exoid, ex_entity_type obj_type, ex_entity_id obj_id, int num_attrs)
Definition: ex_put_attr_param.c:61
ex_block::topology
char topology[MAX_STR_LENGTH+1]
Definition: exodusII.h:354
EX_CLOBBER
#define EX_CLOBBER
Definition: exodusII.h:114
exodusII_int.h
EX_NODAL
Definition: exodusII.h:254
ex_put_info
int ex_put_info(int exoid, int num_info, char *info[])
Definition: ex_put_info.c:102
ex_put_block_params
int ex_put_block_params(int exoid, size_t block_count, const struct ex_block *blocks)
Definition: ex_put_block_params.c:47
ex_block::num_faces_per_entry
int64_t num_faces_per_entry
Definition: exodusII.h:358
ex_put_conn
int ex_put_conn(int exoid, ex_entity_type blk_type, ex_entity_id blk_id, const void_int *node_conn, const void_int *elem_edge_conn, const void_int *elem_face_conn)
Definition: ex_put_conn.c:71
ex_put_map
int ex_put_map(int exoid, const void_int *elem_map)
Definition: ex_put_map.c:85
exodusII.h
ex_update
int ex_update(int exoid)
Definition: ex_update.c:56
ex_put_attr
int ex_put_attr(int exoid, ex_entity_type blk_type, ex_entity_id blk_id, const void *attrib)
Definition: ex_put_attr.c:63
ex_put_init
int ex_put_init(int exoid, const char *title, int64_t num_dim, int64_t num_nodes, int64_t num_elem, int64_t num_elem_blk, int64_t num_node_sets, int64_t num_side_sets)
Definition: ex_put_init.c:80
ex_put_coord
int ex_put_coord(int exoid, const void *x_coor, const void *y_coor, const void *z_coor)
Definition: ex_put_coord.c:113
EX_ELEM_BLOCK
Definition: exodusII.h:261
ex_block::type
ex_entity_type type
Definition: exodusII.h:353
EX_VERBOSE
Definition: exodusII.h:282
ex_put_one_attr
int ex_put_one_attr(int exoid, ex_entity_type obj_type, ex_entity_id obj_id, int attrib_index, const void *attrib)
Definition: ex_put_one_attr.c:63
ex_block::num_edges_per_entry
int64_t num_edges_per_entry
Definition: exodusII.h:357
ex_put_var
int ex_put_var(int exoid, int time_step, ex_entity_type var_type, int var_index, ex_entity_id obj_id, int64_t num_entries_this_obj, const void *var_vals)
Definition: ex_put_var.c:238
ex_copy_string
char * ex_copy_string(char *dest, char const *source, size_t elements)
Definition: ex_utils.c:2174